PDA

View Full Version : No-WWW 301 Redirect



sprsprmman
14 Mar 2008, 02:18 PM
Firstly, I am not a master web developer. I was reading about this no-www to www redirect to avoid duplicate content. I attempted to insert the code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^bmswebsite.com [NC]
RewriteRule ^(.*)$ http://www.bmswebsite.com/$1 [L,R=301]
into my .htaccess file. I then typed in bmswebsite.com into my IE6 browser bar and a "page not found" message appeared. Without the redirect, bmswebsite.com and www.bmswebsite.com appeared without a problem.

Am I doing something wrong, did I not give the server time to adjust, and what exactly is this 301 redirect supposed to do.. make bmswebsite.com appear as www.bmswebsite.com, right?

Any help would be appreciated. Thank you in advance.

David Bowley
15 Mar 2008, 02:15 PM
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

Try doing it with that formatting - I'll be honest and say I'm not sure of the intricate differences but it should work.

Note the couple of extra bits in mine - the extra explamation mark and dollar sign. I know this is to do with regular expressions but not sure what difference they make without reading a reference book. Perhaps someone else on here can shed some light on that.