Server Administration

If you want to redirect all non-www requests to your site to the www version, all you need to do is add the following code in your .htaccess file

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

This will redirect any requests to http://mysite.com to http://www.mysite.com. There are benefits from doing that:

* It will avoid duplicate content in Google
* It will avoid the possibility of split page rank and/or split link popularity (inbound links).
* It’s nicer, and more consistent.

Please make sure that if your site has already been indexed by Google without the www, this might cause unwanted side effects, like lost of PR. I don’t think this would happen, or in any case it would be a temporary issue (we are doing a permanent redirect, 301, so Google should transfer all rankings to the www site). But anyway, use at your own risk ;) !

Another nice way of writing .htaccess is code above is that you can use it for any website, since it doesn’t include the actual domain name.
Redirecting www to non-www

If you want to do www to non-www, the code is very similar:
in your .htaccess file

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

In this case we are explicitly typing the domain name.

I’m sure it is possible to do it in a generic way same as above, but I haven’t had the time to work one out. So remember to change ‘mysite’ with your domain name!, and I’m keeping this post open for all my readers to comment on it and post generic code for www to non-www redirection.

Tags:

It will be surprise for you that I’m writing second post on very next day. Today I had problem with my windows server and not able to access any of my web site hosted.

I have called server people and ask them to fix the issue,  after 30 - 45 mins of call with them they said that I have to run all the services manually and to start IIS services (A technical person is telling me that to restart IIS services you need to restart all the services manually with all there dependency. ohh my GOD).

I don’t wanted to waste my time with server people as my primary business domain was not accessiable from where I get my business. I have started googling and found very good solution to recover my IIS without doing stupid restart all services manually, here is the solution which works very good for me:

Check in C:\Windows\System32\Inetsrv and you’ll find a ‘History’ folder. Within here - hopefully - you’ll find fairly recent backups of the Metabase.XML and MBSchema.XML objects. Before doing the following - be sure to backup the existing Metabase.xml and MBSchema.xml from C:\Windows\System32\Inetsrv first.

Now, rename a recent backup from the ‘History’ folder - renaming a recently Metabase.XML object, and then a recent MBSchema.XML object. Copy / Paste each of these to the C:\Windows\System32\Inetsrv.

Cool !!!, we are almost done :)

Open Command prompt (Start –> run) and type IISRESET, this will restart your service in few seconds.

Hopefully this will get you back to where you need to be.