简体   繁体   English

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

[英]HTAccess Redirect specific URLs to new domain pages and then rest to Root

Having checked other questions and trying the suggested solutions, nothing has worked so far.检查了其他问题并尝试了建议的解决方案后,到目前为止没有任何效果。

I'm trying to redirect certain URLs from the old-domain to URLs on the new-domain, not necessarily with the same page names.我正在尝试将某些 URL 从旧域重定向到新域上的 URL,不一定具有相同的页面名称。 The rest of the URLs should be redirected to the root of the new-domain.其余的 URL 应该重定向到新域的根目录。 This is what I've tried.这是我试过的。 The redirecting of all pages to the root of the new-domain works, just not the individual pages:将所有页面重定向到新域的根目录有效,而不是单个页面:

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]

Thank you.谢谢你。

Don't mix Redirect directive and RewriteRule directives as they come from different Apache modules and their order of execution might be unpredictable.不要混合使用Redirect指令和RewriteRule指令,因为它们来自不同的 Apache 模块,并且它们的执行顺序可能是不可预测的。

You may have your rules as this:你可能有这样的规则:

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]

Make sure to test it in a new browser or test after fully clearing browser cache.请务必在新浏览器中进行测试或在完全清除浏览器缓存后进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM