views:

76

answers:

3

What I'm trying to do is to redirect my website visitors who enter example.com to www.example.com.

I would do this with a standard redirect, but I don't know how to make a site specific to WWW or non-WWW addresses.

I see that Firefox thinks my site is clearly different at the WWW version, because it reloads it without using the cache. How can I make a non-WWW specific index.html page to redirect them to www.example.com?

+2  A: 

Try this mod_rewrite example:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This will append www. to every request that’s host does not start with www. and redirect to it with a permanent redirect. The URI protocol is also preserved but you might want to add a condition to only redirect specific request methods (like GET and HEAD).

Gumbo
A: 

If you are using IIS simply create a new web site, add "mydomain.com" header and use IIS redirect feature to redirect to www.mydomain.com.

Argyris
A: 

You may want to check this link that discusses it with IIS, and is the way that stackoverflow.com is doing it... you would most likely reverse the way things are working.

In Jeff's example, he is removing the {www.} from the url http://www.stackoverflow.com/, but for you, it sounds like you could use his example and do the opposite.

Jeff Atwood's Example for how they did it for StackOverflow.

Richard B