How to redirect a domain to a subdomain using htaccess?

.htaccess is a little new to me!

I have a current site located at www.domain.com and I am creating a new site at new.domain.com.

When the new site is completed, I want to redirect all traffic to the new subdomain.

Also, I want to enable url canonicalization at the same time.

Any help appreciated! thanks mark

+7
redirect .htaccess
source share
6 answers

There are several different solutions. The best of them, both in terms of SEO and from the point of view of users, is an individual 301 redirect. It saves your link juice and at the same time redirects the client to the exact location on the new website.

If you have mod_alias enabled, I would suggest a simple

RedirectMatch 301 ^(.*)$ / http://new.domain.com/$1 

The result command can be executed using

 RewriteEngine On RewriteRule (.*) http://new.domain.com/$1 [R=301,L] 

The second option is the best choice if you need to link several conditions and filters. For example, if you need to redirect only certain hosts or clients depending on the User Agent header.

Remember: mod_redirect takes precedence over mod_alias.

+8
source share

put this in your old htaccess file

 Redirect 301 / http://www.newsite.com/ 

This is a good link to find out about this:

http://www.webweaver.nu/html-tips/web-redirection.shtml

+6
source share
 RewriteEngine On RewriteRule (.*) http://new.domain.com/$1 [R=301,L] 

it just did the trick in my case. Fine! Now all links displayed by Google are redirected from the top domain to the same link in the subdomain.

+1
source share

I would suggest you use this code, so you don’t have to worry about the β€œwww” part of the URL.

 RewriteEngine On RewriteCond %{HTTP_HOST} ^(www.)?mysite\.com$ [NC] RewriteRule ^(.*)$ http://subdomain.mysite.com/ [L,R=302] 
+1
source share

Why not point the old domain to the new site after its completion? I think that you should not point to domains in one directory.

0
source share

How about this solution:

 RewriteRule (.*) http://new.domain.com/$1 [R=301,L] 
-one
source share

All Articles