Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

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.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
817 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...