需要使用htaccess删除图像扩展名

时间:2013-10-03 02:33:46

标签: .htaccess mod-rewrite redirect

当用户来自Google时,我需要将“ example.com/photos/logo.jpg ”更改或重定向到“ example.com/photos/logo ”图像搜索。

因此我使用了:

 RewriteCond %{REQUEST_URI} photos/.*\.(gif|jpg|jpeg|png)$ [NC]
 RewriteCond %{HTTP_REFERER} ^http://www.google.[a-z]{2,4}(.[a-z]{2,4})?/url\?.*$ [NC,OR]
 RewriteCond %{HTTP_REFERER} ^http://www.bing.com/images/search?q=\?.*$ [NC,OR]
 RewriteCond %{HTTP_REFERER} !^http://example.com/.*$ [NC]
 RewriteCond %{HTTP_USER_AGENT} !(.*bot.*|slurp) [NC]
 RewriteRule ^gallery/(.*) /$1 [L,R=301]

1 个答案:

答案 0 :(得分:0)

尝试:

RewriteCond %{HTTP_REFERER} ^http://www.google.[a-z]{2,4}(.[a-z]{2,4})?/url\?.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://www.bing.com/images/search?q=\?.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} !^http://example.com/.*$ [NC]
RewriteCond %{HTTP_USER_AGENT} !(.*bot.*|slurp) [NC]
RewriteRule ^photos/(.*)\.(jpe?g|png|gif)$ /photos/$1 [L,NC,R=301]