问题
I have a viral image site where people can view funny gifs. A lot of people on reddit are sharing the raw .gif files however, rather than the page with .gif embedded. This is fine - but I'd like to redirect all people viewing raw image .gifs to a handler page called shareraw.php (located in root directory). This handler page will look exactly the same - just with a share link and button to check out the rest of the site.
Example of raw image location: http://gifsec.com/wp-content/uploads/GIF/2015/03/Scared-Reaction-Gif.gif
Share page location: http://gifsec.com/shareraw.php
Here is my code currently which is not working. When I go to a raw gif, nothing happens:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?gifsec.com\.com/ [NC]
RewriteCond %{REQUEST_URI} /uploads/GIF/.*\.gif$ [NC]
RewriteRule ^(.*)$ /shareraw.php?img=$1 [R,L]
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
回答1:
Ok, we redirect the gif to the dedicated page. How will that page render the gif? Again, using gif file? loop begins.
You can achieve it using combination of PHP with htaccess but you will have to change image display at all location. (though not foolproof)
Depending on the site size, efforts can be estimated.
来源:https://stackoverflow.com/questions/29382639/redirect-raw-gif-files-to-handler-page-via-htacces-my-code-doesnt-work