Reputation: 1782
I am trying to redirect an old website to a new website. I see the old site as two parts. The blog articles and everything else. I would like the blog articles to be redirected to their new locations on the website, while keeping the same URL (more or less). I would like everything else to redirect to the new site's home page.
Requirements:
/blog
part) but on the new domainExample:
oldsite.com/
--> www.newsite.com
www.oldsite.com/register
--> www.newsite.com
www.oldsite.com/pictures/cats
--> www.newsite.com
www.oldsite.com/blog
--> blog.newsite.com
www.oldsite.com/blog/cool-cats
--> blog.newsite.com/cool-cats
Upvotes: 0
Views: 3012
Reputation: 45829
I assume different physical servers?
At the top of your .htaccess file on the old site, try the following:
RewriteEngine On
RewriteRule ^(blog)(/.*)? http://$1.newsite.com$2 [R=302,L]
RewriteRule .* http://www.newsite.com/ [R=302,L]
This first redirects the "blog" URLs then redirects everything else. The order is important.
Change the 302
(temporary) redirect to a 301
(permanent) when you are sure it's working OK. (302 redirects won't be cached by the browser - in case of an error.)
However, I would recommend not redirecting multiple pages to a single home page on the new site if you can help it. This is generally a bad experience for users and Google is likely to treat it as a soft-404 and ignore it anyway.
Upvotes: 1
Reputation: 4302
Put the following code @ oldsite , main directory, .htaccess file:
RewriteEngine on
RewriteRule !^blog ($|/) http://www.newsite.com%{REQUEST_URI} [L,R=301]
# above line will redirect entire site to new site and exclude blog directory.
Then ,put the following code @ the oldsite.com/blog/ directory .htaccess file :
RewriteEngine On
RewriteRule ^(.*)$ http://www.blog.newsite.com/$1 [L,R=301]
# above line will redirect all requested url for oldsite.com/blog/ directory
# to blog.newsite/ with same extensions and if you remove $1 it will
# be redirected to index @ blog.newsite.com
If there are some blog/SubDirectories/ , check if there are no .htaccess in them , or they existing but has nothing , so no problem but if they have some rules ,Make sure that it is adapted to not effect /blog/ directory .htaccess rules
Upvotes: 1