Here is what I have for now in my .htaccess
and this should work in future:
以下是我现在在.htaccess中所拥有的内容,这应该适用于未来:
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:
问题是:
how can I make this rewrite /tmp/some_image.png -> /image.php?file=some_image.png
怎样才能重写/tmp/some_image.png - > /image.php?file=some_image.png
I've tried to make my own rule, but without success.
我试图制定自己的规则,但没有成功。
Thanks.
谢谢。
2 个解决方案
#1
13
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.
是/ tmp您的Web服务器可以访问的目录吗?我希望它是一个单独的/ tmp文件夹而不是服务器的实际/ tmp,因为这会带来安全风险。
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:
无论如何,如果图像是一个物理文件,那么你需要在重写之后将其放入强制HTTPS,并在条件检查之前检查它是否是文件或目录:
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)
或者,如果你不在乎(一切都是你的tmp文件夹中的图像。虽然我不推荐这个)
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.
如果它不是物理文件,您可以在规则的最后放置其中任何一个。
#2
-1
Correct answer is:
正确的答案是:
RewriteRule ^/?tmp/(.*\.png)$ captcha.php?file=$1 [L]
thx goes to Humbedooh@freenode
thx去了Humbedooh @ freenode
#1
13
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.
是/ tmp您的Web服务器可以访问的目录吗?我希望它是一个单独的/ tmp文件夹而不是服务器的实际/ tmp,因为这会带来安全风险。
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:
无论如何,如果图像是一个物理文件,那么你需要在重写之后将其放入强制HTTPS,并在条件检查之前检查它是否是文件或目录:
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)
或者,如果你不在乎(一切都是你的tmp文件夹中的图像。虽然我不推荐这个)
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.
如果它不是物理文件,您可以在规则的最后放置其中任何一个。
#2
-1
Correct answer is:
正确的答案是:
RewriteRule ^/?tmp/(.*\.png)$ captcha.php?file=$1 [L]
thx goes to Humbedooh@freenode
thx去了Humbedooh @ freenode