Web Hosting Talk







View Full Version : force one adress to access a website


Renard Fin
08-14-2006, 03:22 PM
Hi guys, sorry for the title which is not that much of a expressive one but it's the most appropriate I had in mind :)

So here is my "problem" :

How may I detect that someone goes to my website with or without the "www" of the adress.

I'm building a MVC application ... which will use subdomain to ease te application selection.

I want then that if someone access mydomain.com(without "www") will be automatically redirected to www.mydomain.com

stdunbar
08-14-2006, 04:00 PM
On the assumption that you're using Apache, one way would be to create a VirtualHost for "mydomain.com" that is just:


<VirtualHost *>
ServerName mydomain.com
Redirect permanent / http://www.mydomain.com/
</VirtualHost>


I'm sure you could use mod_rewrite magic too though I always mess up the syntax with that :)