Always use www.domain.com instead of domain.com!

If you wish to use always http://www.domain.com instead of http://domain.com, in ASP .Net a solution is to modify the file global.asax:

protected void Application_BeginRequest( object sender, EventArgs e){
   //check the request to make it starts with www
   //and is not localhost (dev)
   if (!Request.Url.Host.StartsWith( "www"
) && !Request.Url.IsLoopback)
   {
      //now ... redirect.
      
UriBuilder builder = new UriBuilder
(Request.Url);
      builder.Host =
"www."
+ Request.Url.Host;
      Response.Redirect(builder.ToString(),
true
);
   }
}

 

There are and other solution, like httpd.ini, or depending what you use. In PHP (Apache) I solve this by adding in the top of .htaccess file this code:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

 

Why to use this? The 1st  reason is for seo (you will see that in a future article) and another reasons is that it looks more profesional.


Posted by: admin
Posted on: 9/8/2009 at 3:14 AM
Tags: , , , , , ,
Categories: ASP | SEO | WWW
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed