Rebranding: how do I redirect my website to a new domain, and blog to a subdomain?

Rebranding: how do I redirect my website to a new domain, and blog to a subdomain? - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about seo, htaccess, 301-redirect, apache2, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I have a website that I am rebranding and using a new domain name for. Right now it is primarily a blog hosted at the root.



I am going to be redirecting from www.old.com to www.new.com, and I also want to move my blog to blog.new.com. Currently www.old.com doesn't serve any subdomains.



Based on the research I've done, it would seem that I need to use 301 redirects because these should be permanent. I just don't really know what I need to do to setup these redirects. Should I use mod_rewrite?



My sites are hosted on Dreamhost so any Apache configuration that I would need to do I believe I'd have to do in an .htaccess file.


Solution :

All of the following code will be placed in a file called .htaccess in your root web directory and mod_rewrite enabled on your server.



Changing the domain is easy to do. The following snippet should do it:



Options +FollowSymlinks
RewriteEngine On
RewriteCond %HTTP_HOST ^(www.)?old.com$ [NC]
RewriteRule ^(.*)$ http://www.new.com/$1 [R=301,L]


To move your blog you can use the following snippet (assuming your blog is in a subdiretory called /blog):



RewriteCond %HTTP_HOST ^blog.old.com$
RewriteCond %REQUEST_URI !^blog/
RewriteRule ^(.*)$ http://blog.new.com/$1 [L,QSA]

Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect