.htaccess rewrite image file to php script

前端 未结 2 723
迷失自我
迷失自我 2020-11-30 10:41

Here is what I have for now in my .htaccess and this should work in future:

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) http         


        
相关标签:
2条回答
  • 2020-11-30 11:06

    Correct answer is:

    RewriteRule ^/?tmp/(.*\.png)$ captcha.php?file=$1 [L]
    

    thx goes to Humbedooh@freenode

    0 讨论(0)
  • 2020-11-30 11:15

    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.

    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.

    0 讨论(0)
提交回复
热议问题