arifix
arifix

Reputation: 750

Migrating domain by .htaccess

I need some help with migrating from one domain to another. There's 2 issues to this problem...

ISSUE 1: Right now the domain1 has links like http://www.domain1.com/archives/this-is-an-article/

I need to 301 redirect in htaccess to http://domain2.com/this-is-an-article/

So the domains change and there's an additional /archives/ in there that needs to be cut off.

ISSUE 2: I have a subdomain on domain1 that needs to be 301 redirect to just the home page of domain2. example: http://subdomain.domain1.com/hello-there/ should 301 redirect to http://domain2.com/

Upvotes: 1

Views: 66

Answers (1)

anubhava
anubhava

Reputation: 785481

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^archives/(.*)$ http://domain2.com/$1 [L,NC,R=301]

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteRule ^ http://domain2.com/? [L,NC,R=301]

Upvotes: 2

Related Questions