简体   繁体   中英

301 redirect to new domain and new name folder

I'm going to change my domain name but also need to change and one folder name on url structure. I want "www.example.com/name" to become "new-example.com/new-name".

I have this code for .htaccess:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(?:name/?)?(.*)$ http://new-example.com/$1 [L,R=301,NC,NE]

but this code remove "name" folder on redirected links. How can i change folder name and not remove it?

Would this work?

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^name/(.*)$ http://new-example.com/new-name/$1 [L,R=301,NC,NE]

Try this rule as your very first rule:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^name(/.*)?$ http://new-example.com/new-name$1 [L,R=301,NC,NE]

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ http://new-example.com/$1 [L,R=301,NE]

Clear your browser cache before testing this change.

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