[英].htaccess: 301 redirect not working in .htaccess in rewritten root path
我有一個名為example.com
的域,它指向我服務器上的/public_html/
。
在/public_html/.htaccess
我有以下代碼將我的域example.com
的根路徑更改為/public_html/example_path/
:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule !example_path/ /example_path%{REQUEST_URI} [L]
這工作得很好。
現在,我想將example.com/test.png
重定向到example.com/images/test.png
。 為此,我在/public_html/example_path/.htaccess
使用以下代碼:
RewriteEngine On
Redirect 301 /test.png /images/test.png
不幸的是,這不起作用,沒有重定向。 只有當我將代碼放入/public_html/.htaccess
而不是/public_html/example_path/.htaccess
,重定向才有效。
為什么?
在你的/public_html/.htaccess
在example_path
規則之前有重定向規則:
RewriteEngine On
RewriteRule ^test\.png$ /images/test.png [L,NC,R=301]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule !example_path/ /example_path%{REQUEST_URI} [L,NC]
請注意,您不能在/example_path/.htaccess
設置圖像重定向規則,因為您的圖像 URL 沒有/example_path/
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.