简体   繁体   中英

Redirect all but a few to new homepage with htaccess?

We have moved our site to a new domain and a new system. I am looking for a way to 301 redirect a bunch of urls to new custom urls on another domain, and send all the other pages to the homepage of the new domain. How can I achieve this?

I currently have the following in my .htaccess:

RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.com/ [R=301,L]

I thought this would've redirected everything to the homepage, but oldomain.com/page would still send me to newdomain.com/page.

Any help or a nod to the direction would be highly appreciated!

You need to place all custom redirects before generic catch-all redirect in the end:

RewriteEngine on

RewriteRule ^page1/?$ http://newdomain.com/newPage1 [R=301,L,NC]
RewriteRule ^page2/?$ http://newdomain.com/newPage2 [R=301,L,NC]
RewriteRule ^page3/?$ http://newdomain.com/newPage3 [R=301,L,NC]

RewriteRule ^ http://newdomain.com/ [R=301,L]

Make sure you test this in a new browser to avoid browser caching issues.

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