的.htaccess改写镜像文件的PHP脚本
下面是我现在在我的的.htaccess
,这应该在今后的:
Here is what I have for now in my .htaccess
and this should work in future:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
现在的问题是:
The question is:
我怎样才能使这个重写 /tmp/some_image.png - > /image.php?file=some_image.png
how can I make this rewrite /tmp/some_image.png -> /image.php?file=some_image.png
我试图使自己的统治,但没有成功。
I've tried to make my own rule, but without success.
感谢。
是的/ tmp目录由Web服务器访问?我希望这是一个独立的/ tmp的文件夹,而不是服务器的实际/ tmp目录因为这将是一个安全隐患。
Is /tmp a directory accessible by your web-server? I'm hoping it's a separate /tmp folder and not the actual /tmp of the server as that would be a security risk.
总之,如果图像是一个物理文件,那么你需要你重写后,把这个给力HTTPS和之前的条件检查,如果它是一个文件或目录:
Anyway if the image is a physical file then you need to put this after your rewrite to force HTTPS and before the conditions checking if it's a file or directory:
RewriteRule ^/tmp/([^\.]+)\.png$ /image.php?file=$1.png [NC,L]
您可以检查其他的扩展,以及:
You could check for other extensions as well:
RewriteRule ^/tmp/([^\.]+)\.(png|jpg|gif)$ /image.php?file=$1.$2 [NC,L]
或者,如果你不小心(一切都在你的临时文件夹中的图像。虽然我不建议这一点)
Or if you don't care (everything is an image in your tmp folder. Though i wouldn't recommend this)
RewriteRule ^/tmp/(.*)$ /image.php?file=$1 [NC,L]
如果它不是一个物理文件,你可以把其中任何一个在你的规则结束。
If it's not a physical file you can put any one of these at the end of your rules.