简体   繁体   中英

Redirect old domain to subdirectory of new domain via htaccess

I have a Wordpress blog running on Apache, which I am moving on to another wordpress site. On the new site, the blog will be in a subdirectory, with its URL structure intact.

I would like to redirect all traffic from pages of the old blog to the corresponding page within the subdirectory of the new site.

This is what I have so far. It is working to redirect the root of the blog to the subdirectory of the new site, but posts on the blog are not working - the page just hangs for a few minutes and then displays the blog without any css.

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^blogname.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.newsite.com$
RewriteRule (.*)$ http://newsite.com/blogname/$1 [R=301,L]
</IfModule>

EDIT: More detail on the error:

blogname.com redirects successfully to http://newsite.com/blogname/ . However, if I go to blogname.com/page-name/ then the page takes several minutes to load. At the bottom of the screen it says "Waiting for newsite.com..., transferring data from newsite.com ". When the page eventually loads, it is blogname.com/page-name (hasn't redirected) , but the style/javascript hasn't loaded, because those files are redirecting.

Any help gratefully appreciated.

I discovered this problem was caused by the Wordpress plugin "FV Top Level Categories". I've disabled that and now the above redirect is working fine.

Thanks to all who offered help.

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