简体   繁体   中英

Redirect to a new domain & change url structure htaccess

I am trying to redirect a wordpress blog from an old domain to a new domain and changing the structure of the urls on the new domain.

So I want www.domainA.com to redirect to test.domainB.com/folder/ and www.domainA.com/2001/12/some-post to redirect to test.domainB.com/folder/some-post

This is what I currently have in my htaccess file. I have managed to achieve my second objective, but if you go to www.domainA.com , it does not redirect to test.domainB.com/folder/ All the other pages redirect properly aside from the homepage.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteRule ^([0-9]+)/([0-9]+)/(.*)$ http://test.domainB.com/folder/$3 [R=301,NC,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

I am sure I am missing something elemetary, but I can't seem to figure it out :(

Try this code :

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteRule ^/?\d+/\d+/(.*)$ http://test.domainB.com/folder/$1 [NC,L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteRule ^/?$ http://test.domainB.com/folder/ [NC,L,R=301]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]

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