我已经生成了.htaccess规则,该规则将请求图像重定向到源图像或包含该图像的网页。但是,它没有用,显然我做错了。任何想法都表示赞赏!
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/manufacturers/$1/$2/$3.jpg
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
RewriteRule (.*) http://www.example.com/$1/$2
请求示例:www.example.com/manufacturers/audi/audi-a8/audi-a8-1.jpg
应重定向到:www.example.com/audi/audi-a8 /
答案 0 :(得分:2)
这一行有问题:
RewriteCond %{REQUEST_URI} ^/manufacturers/$1/$2/$3.jpg
由于$1
的{{1}},$2
等在RewriteCond
的RHS上不可用。您可以改用此规则:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example\.com [NC]
RewriteRule ^manufacturers/([^/]+)/[^/]+/([^/]+)/[^/.]+\.jpe?g$ /$1/$2 [L,NC,R=302]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example\.com [NC]
RewriteRule ^manufacturers/([^/]+/[^/]+)/[^/.]+\.jpe?g$ /$1 [L,NC,R=302]