Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirect

Redirect from http:// to http://www

         

mikem1986

10:00 am on Jun 8, 2009 (gmt 0)

10+ Year Member



Hi guys

Ive just set up a new website but each time i go to the domain it cuts out the www. at the beginning

How do i use .htaccess to make sure it always redirects to the www. version

Cheers

Samizdata

6:51 pm on Jun 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This kind of question has been answered countless times in the Apache forum:

[webmasterworld.com...]

However, unless you are on a dedicated server it is extremely unusual for a hosting company not to have an alias in place so that the "www" will also work (and not redirect) - you might want to check the settings in your hosting control panel.

...

bill

1:59 am on Jun 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This topic gets discussed all over WebmasterWorld. I'm a fan of the www-less site and would leave things as they are, but if you want to redirect the other way then a search of WebmasterWorld [google.com] will turn up some threads that will help.

Gomvents

6:23 pm on Jun 9, 2009 (gmt 0)

10+ Year Member



Open Notepad or other text editor, replace example.com with your url, paste in the text below and save as .htaccess and upload this file to the root of your hosting.

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

mikem1986

8:26 pm on Jun 10, 2009 (gmt 0)

10+ Year Member



Thanks gomvents!