htaccess help..no idea what to do!

They have: 5,633 posts

Joined: Jan 1970

Greetings,
Currently I want to do something when someone visits my site.

When someone comes to the URL:
http://domain.com (without www)

I want them to be changed to:
http://www.domain.com (with www).

I have searched around for ways of doing this with htaccess mod_rewrite or just plain redirection, can't find a thing. Thanks for your help!

Mark

druagord's picture

He has: 335 posts

Joined: May 2003

you could use mod_rewrite for that but i don't think it can be done in a htaccess file if you don't have access to the server config file. the easiest way is to have domain.com go to a different index file and have a redirect there. Another way would be to use javascript to detect the URL and redirect when necesary use this only as last resort.

IF , ELSE , WHILE isn't that what life is all about

mairving's picture

They have: 2,256 posts

Joined: Feb 2001

You can do it through mod_rewrite or if you have access to the http.conf file, you can redirect it.

So it can be done. My question is why do you want to do it? Generally when you setup your site, you will setup the DNS record to point to the domain.com and create an alias for the domain.com to point to the same place. It is not a good idea to have the www point to another IP address and can cause confusion. So can you tell the reason that it is setup that way?

And...welcome to WMF.

Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.