简体   繁体   中英

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. The rest of the URLs should be redirected to the root of the new-domain. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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