hockey2112
hockey2112

Reputation: 506

Redirect from old subdomain/domain to new domain using htaccess

My website was on a subdomain, like this: mysite.primarydomain.com. The primarydomain.com DNS was managed by a third party who owns the primarydomain.com url.

My new website is now on on mysite.com. I had the third party add an a record that points mysite.primarydomain.com to my new website's IP address. How can I then redirect that mysite.primarydomain.com domain to mysite.com? Would that be via htaccess? Or via cpanel configuration?

Thanks!

Upvotes: 1

Views: 2163

Answers (3)

Vishal Barot
Vishal Barot

Reputation: 49

Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^subdomain.domain\.com$ [NC] RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

Upvotes: 0

hockey2112
hockey2112

Reputation: 506

Thanks Jon Lin for your answer. It inspired me to find a very easy method in cpanel...

In the primarydomain.com, I created a subdomain for "mysite.primarydomain.com".

I then went to "Redirects". Since I added the "mysite." subdomain, it gave me the option to create a redirect using that subdomain. So I created a redirect for mysite.primarydomain.com to point to mysite.com.

I then was able to create a few other redirects to help keep some of their old links live, such as "mysite.primarydomain.com/about".

Thanks!

Upvotes: 0

Jon Lin
Jon Lin

Reputation: 143906

There's probably a cpanel configuration to do this pretty easily, probably something like this: http://docs.cpanel.net/twiki/bin/view/AllDocumentation/WHMDocs/SetupForwarding

But you can also add an htaccess file to the document root of the mysite.primarydomain.com site, that says:

Redirect 301 / http://mysite1.com/

or if the document root is shared, you'll need:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\primarydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mysite1.com/$1 [L,R=301]

Upvotes: 2

Related Questions