我正在尝试将特定图片重定向到特定网址(如果直接浏览)。以下是行不通的:
Redirect 301 /images/image1.jpg /page.html
我在这里做错了吗?
以下是我的整个htaccess文件:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9-]+)$ /item.php?slug=$1 [L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
RewriteRule ^sitemap.xml$ sitemap.php
ErrorDocument 400 /error/
ErrorDocument 403 /error/
ErrorDocument 404 /error/
ErrorDocument 405 /error/
ErrorDocument 408 /error/
ErrorDocument 500 /error/
ErrorDocument 502 /error/
ErrorDocument 504 /error/
Options -Indexes
RewriteCond %{HTTP_REFERER} ^$
RewriteRule ^/includes/content/upload/tarantula-spider-dog-costume-459.jpg$ /tarantula-spider-dog-costume [NC,L]
RewriteCond %{QUERY_STRING} c=2
RewriteRule ^category\.php$ /categories/outdoors? [L,R=301]
RewriteCond %{QUERY_STRING} c=3
RewriteRule ^category\.php$ /categories/pet-stuff? [L,R=301]
RewriteCond %{QUERY_STRING} c=4
RewriteRule ^category\.php$ /categories/geeky-stuff? [L,R=301]
RewriteCond %{QUERY_STRING} c=5
RewriteRule ^category\.php$ /categories/toys? [L,R=301]
RewriteCond %{QUERY_STRING} c=6
RewriteRule ^category\.php$ /categories/apparel? [L,R=301]
RewriteCond %{QUERY_STRING} c=7
RewriteRule ^category\.php$ /categories/ridiculous? [L,R=301]
RewriteCond %{QUERY_STRING} c=8
RewriteRule ^category\.php$ /categories/kid-stuff? [L,R=301]
RewriteCond %{QUERY_STRING} c=9
RewriteRule ^category\.php$ /categories/food-drink? [L,R=301]
RewriteCond %{QUERY_STRING} c=10
RewriteRule ^category\.php$ /categories/home-kitchen? [L,R=301]
RewriteCond %{QUERY_STRING} c=11
RewriteRule ^category\.php$ /categories/gag-gifts? [L,R=301]
RewriteCond %{QUERY_STRING} c=12
RewriteRule ^category\.php$ /categories/books? [L,R=301]
RewriteCond %{QUERY_STRING} c=13
RewriteRule ^category\.php$ /categories/halloween? [L,R=301]
RewriteCond %{QUERY_STRING} c=14
RewriteRule ^category\.php$ /categories/christmas? [L,R=301]
RewriteCond %{QUERY_STRING} c=15
RewriteRule ^category\.php$ /categories/valentines-day? [L,R=301]
RewriteCond %{QUERY_STRING} c=16
RewriteRule ^category\.php$ /categories/link-roundup? [L,R=301]
RewriteCond %{QUERY_STRING} c=1
RewriteRule ^category\.php$ /categories/gadgets? [L,R=301]
答案 0 :(得分:1)
试试这个
RewriteEngine On
RewriteRule ^images/image1.jpg$ page.html [R=301,NC,L]
您可以在http://htaccess.madewithlove.be
进行测试根据您的编辑,更新第19行,如下所示:
RewriteCond %{HTTP_REFERER} ^$
RewriteRule ^includes/content/upload/tarantula-spider-dog-costume-459.jpg$ /tarantula-spider-dog-costume [R=301,NC,L]
从^/includes...
删除前导斜杠并添加R=301
。当我在上面提到的.htaccess测试仪中测试它时,它可以工作。
答案 1 :(得分:0)
您可以尝试
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^$
RewriteRule ^/images/image1.jpg$ /page.html [NC,L]
答案 2 :(得分:0)
我的理解
1。 image1.jpg
应始终显示在您网站的网页中。
2。当图片的网址直接调用时,它应该使用以下两个选项之一显示html页面page.html
的内容,而不是显示图片:
A )在浏览器中保留相同的图片网址,但只显示
page.html
内容{page.html
不包括image1.jpg
时)。
B )通过重定向到page.html
更改浏览器中的网址(此
页面可能包含image1.jpg
)
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^$
RewriteRule ^images/image1.jpg$ page.html [NC,L]
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^$
RewriteRule ^images/image1.jpg$ page.html [R=301,NC,L]