Friday, October 31, 2008

Force a website to use WWW using IIS

Some times you need to redirect all request to http://example.com/ to http://www.example.com/ . To achieve this you can write code to see if request is for http://example.com/ and redirect to http://www.example.com/ . We can also achieve this using just IIS (i think it will be faster than Code base solution) taking advantage of host headers. Add hostheader http://www.example.com/ to your website (see how to this in this link http://www.visualwin.com/host-header/ ) . Now create another new website with exact same settings as your first website exept host header value it should be example.com. Now right click your new website in IIS select properites and goto Home directory tab. select "A redirection to URL" radio button, in the "Redirect to" text box enter http://www.example.com/ . See the screen shot below for more details

No comments: