Top Menu

How to Redirect Non-WWW to WWW URL

Often when hosting a site, we find that the www is ripped off and just the domain name is displayed on the URL. Search engines would consider this to be a different domain. For example, though http://seo-mind.com and http://www.seo-mind.com is similar, search engines tend to recognize them as two separate domains. As a result, the page rank is split among the domains and loses out on link popularity.

Resolution:
The correct way to resolve this issue is to have a 301 redirect on the server pointing to either a www or a non-www domain alone. To do this, one has to instruct the server to redirect any faulty domains. This is quite easy in a Apache server with a .htaccess file. We will now discuss how this can be done on a Apache and on a IIS server.

WWW 301 Redirect on Microsoft IIS Server

  1. In IIS, create a new virtual or IP-based website with the name http://yourwebsite.com
  2. Check the server header to find out if the server response is 200 OK.
  3. Now, add the ASP code below to your default home page in http://yourwebsite.com
  4. < %@ Language=VBScript %>
    < % Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", http://www.yourwebsite.com
    %>

  5. Your redirect is now completed. Check using your browser with a non-www url to see if the domain gets redirected.

WWW 301 Redirect on Apache Server

  1. Find out from your hosting provider if Apache Rewrite Module is turned on. If you have a dedicated server or you have access to the httpd.conf file, you can enable the Rewrite yourself by just uncommenting the line below:
  2. LoadModule rewrite_module modules/mod_rewrite.so

  3. Now, download the .htaccess file from the root location on your server and make a copy of it and store the copy separately on your local system. This is important because if the .htaccess file that you modified does not work, you would have to replace it with the original file or you might face serious website issues.
  4. Now, open the .htaccess file using Notepad or EditPlus and just add the following codes on it.RewriteEngine On
    RewriteCond %{HTTP_HOST} ^yourwebsite.com
    RewriteRule (.*) http://www.yourwebsite.com/$1 [R=301,L]
  5. Upload the file back to the server and test using the browser if the redirect works.
  6. If it does not work or if you face any other issues, please upload the .htaccess copy that you stored in your local system on the server immediately.

, , ,


No comments yet.

Leave a Reply