Hello Guest, if you read this, it means you are not registered. Click here to register a few simple steps, you will enjoy all the features of our Forum. Please note that nicknames are prohibited lewd or meaningless (no numbers or letters at random) and introduce yourself in the section for you to meet our community.
Using htaccess to manage redirection issues - Blogs - GOZEN Host Forums
View RSS Feed

GOZEN Host blogs

Using htaccess to manage redirection issues

Rate this Entry
by , 04-27-2012 at 09:14 AM (2800 Views)
Redirecting using htaccess is simply the best way to solve issues that might come up specially after a domain name change. Itís true that when a web host is changed the only thing that we have to do is change our DNS settings and the new server will resolve in a few hours (usually 4 to 48 hours depending on our registrar and ISP).

However when we are about to change our domain name then we must redirect the old one to the new and all the indexed links so we wonít loose any rank/traffic.
Also we have to do this in order to avoid duplicate content penalty which is something that search engines find not acceptable and both your domains could be penalized or, worse, banned from search engine listing. Instead of the old way with redirection pages the best way is to use a permanent (301) redirection and here is where .htaccess redirection and mod rewrite (apache server) is going to provide help.
Itís a lot different when you just change hostís than when you change your domain name or if you are moving a sub domain to something else like your root domain.

Moving old domain to a new domain using the same hosting account
In case you want to replace your primary domain with your new domain i am afraid that this is something you canít do by your selfís and this is why your primary domain is connected with you hosting account and all add-on and parked (alias) domains are connected with your main domain. But in our case you can contact GoZen Host Support and fire us a ticket so we can replace your primary domain with your new domain at no cost at all and in any case if your host is good enough you can ask them to do that for you.

Use your parked domain as main domain
A parked domain which is actually an alias, is pointing to your root (only if itís parked on your account) and that means that itís the same as your main domain. So in this case you can use this domain as ęmain domainĽ on your account and redirect permanently traffic from your old domain to your new domain. This is not a problem at all but what you should be aware of is that you must keep your old domain also in good health because if your old domain expires or if itís removed all other domains will disappear.
In this case (alias as main domain) itís not necessary to move any page from your site, but itís necessary to remove any instance of your old domain at any of your pages (internal links), and this is also a good place to mention that using relative links (links without the full url) you donít have to change anything again. The only thing you should do is add the following code to your .htaccess file so you can redirect your primary (old) domain to the new one (previews parked, alias) domain.

Code:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.olddomain.com$[OR]
RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
With this setup every request for your olddomain.com/index.html is permanently redirected (with 301 code) to newdomain.com/index.html
The only problem is if you had your /stats/ folder setup this way.
Now this is also redirected from olddomain.com/stats/ to newdomain.com/stats/ so in this case you will need to disable the redirection in order to be able to access that folder.

Using Add-on domain as main domain
The difference between a parked domain and an add on domain is that the second one is pointed to a sub directory of the main (primary) domain ( i.e. main domain yourdomain.com and addondomain.com is your add on domain so the addondomain.com is pointing to yourdomain.com/addondomain/ ) while the alias (parked) domain is pointing to root. In this case we need to move (copy) all files from addondomain.com to a folder under yourdomain.com and then we should redirect the root to /addondomain/ .
In order to achieve that redirection you need to add the following code (similar to the code we have above)

Code:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$[OR]
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule ^(.*)$ http://www.yourdomain.com/addondomain/$1 [R=301,L]
Change your domain name and redirect old domain to new one on a different account
This is one of the best wayís to change a domain name. Simply ask your host to setup a new account host your new domain on that account test if everything is working fine and then add a redirection from your old domain (account) to your new domain but also keep your old domain and account for a few months with the redirection on. Itís even better if you do that for a year.
When you are sure that the new domain is indexed on search engines and google PR is update for the new domain, double check if there are no links pointing to the old domain and then you can use your old domain for something else (not the same content) itís not advised to let that domain name go since someone else might take advantage of that although after that period actually you can do what ever you have decided to do with your old domain name.

And hereís the code for you to do that :
Code:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$[OR]
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule ^(.*)$ http://www.yourNEWdomain.com/$1 [R=301,L]
The following example is about a famous sub domain that you want to move to the new domain on an other account and you can simply do thaw using the following lines in your .htaccess file.
Code:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursite.hosting.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.hosting.com$
RewriteRule (.*)$ http://www.yournewdomain.com/$1 [R=301,L]
This code could also be used if you had a sub-domain without a domain letís say like famus-sub-domain.wordpress.org

SEO tips with .htaccess
One big problem many web developers have to deal with, is double links, this is so important that in many cases your website faces issues with search engines because of the double content, and this could be like : gozenhost.com/page.html and www.gozenhost.com/page.html .
Also believe it or not there are still sites you canít reach without using WWW and even thought this might be a server configuration problem (or DNS) you truly have to deal with it. I prefer to use www for my links and this is why many browsers like it better, even thought this is not a standard, so in this case i use the following code on my .htaccess files.

Code:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^gozenhost.com
RewriteRule ^(.*) http://www.gozenhost.com/$1 [R=301,L]
If you donít like the www and you prefer to use http://gozenhost.com links then you can reverse the setting like this:
Code:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^www.gozenhost.com
RewriteRule ^(.*) http://gozenhost.com/$1 [R=301,L]
You can test this very easy, just try it on your browser (make sure your browsers cache is cleared in order to see the results immediately.

Itís certain that if there is only one version of your domain out thereÖ your Google PR will boost.

Submit "Using htaccess to manage redirection issues" to Digg Submit "Using htaccess to manage redirection issues" to del.icio.us Submit "Using htaccess to manage redirection issues" to StumbleUpon Submit "Using htaccess to manage redirection issues" to Twitter

Updated 10-12-2015 at 08:06 AM by GOZEN

Categories
Web Optimization Tips

Comments