简体   繁体   中英

Redirect all deeplinks to new domain with slight change in all URL's

I am trying to redirect all pages of DomainA to DomainB but with a slight change in the URL structure.

For example:

I need to redirect:

http://www.domaina.com/cars/fast-motors -> http://www.domainb.com/vehicles/fast-cars http://www.domaina.com/cars/slow-motors -> http://www.domainb.com/vehicles/slow-cars http://www.domaina.com/cars/red-motors -> http://www.domainb.com/vehicles/red-cars http://www.domaina.com/cars/pink-motors -> http://www.domainb.com/vehicles/pink-cars

I can manage to redirtect allurls to new domain like this:

RewriteEngine on RewriteRule ^cars/(.*)$ http://www.domainb.com/vehicles/ $1 [R=301,L]

But I cant work out how to change the last word. theres thousands of these urls so i cant manually do a list of 301s. I basically need to redirect all urls to new domain but switch /cars/ to /vehicles/ and -motors to -cars .

Any help appreciated.

thanks

You can use this in your .htaccess file :

RewriteEngine On
RewriteRule ^cars/(.*)-motors/? http://www.domainb.com/vehicles/$1-cars [R=302,L]

Change [R=302] for [R=301] when test work well.

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