HTAccess 将特定 URL 重定向到新的域页面,然后休息到根目录



检查了其他问题并尝试了建议的解决方案后,到目前为止没有任何效果。

我正在尝试将某些 URL 从旧域重定向到新域上的 URL,不一定具有相同的页面名称。其余 URL 应重定向到新域的根目录。这就是我尝试过的。将所有页面重定向到新域的根目录有效,而不是单个页面:

RewriteEngine on
Redirect 301 /travel/ferry.html http://www.new-domain.com/ferry/
RewriteEngine off
#
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?old-domain.com$ [NC]
RewriteRule ^ http://www.new-domain.com/? [R=301,L]

谢谢。

不要混合Redirect指令和RewriteRule指令,因为它们来自不同的 Apache 模块,它们的执行顺序可能是不可预测的。

您的规则可能如下:

RewriteEngine on
# keep specific redirect here
RewriteRule ^travel/ferry.html$ http://www.new-domain.com/ferry/ [L,NC,R=301]
# redirect rest of the URLs to root
RewriteCond %{HTTP_HOST} ^(?:www.)?old-domain.com$ [NC]
RewriteRule ^ http://www.new-domain.com/? [R=301,L]

确保在新浏览器中对其进行测试,或在完全清除浏览器缓存后进行测试。

相关内容

最新更新