Jump to content
Web Marketing Help Forum
Sign in to follow this  
JASPER

How to force www or non-www in htaccess

Recommended Posts

I am trying to do this for my mobile version from www.m.  to just m.

 

I have used this code:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.m\.brand-newhomes\.co\.uk [NC]
RewriteRule ^(.*)$ [url=http://m.brand-newhomes.co.uk/]http://m.brand-newhomes.co.uk/[/url]$1 [L,R=301]
 
 
RewriteRule ^index.php$ /index.htm
RewriteRule ^index.shtml$ /index.htm
RewriteRule ^index.asp$ /index.htm
RewriteRule ^index.aspx$ /index.htm 
RewriteRule ^index.cfm$ /index.htm
RewriteRule ^index.pl$ /index.htm
RewriteRule ^default.asp$ /index.htm
RewriteRule ^default.aspx$ /index.htm
RewriteRule ^default.htm /index.htm
RewriteRule ^(.*)index.htm$ [url=http://m.brand-newhomes.co.uk/]http://m.brand-newhomes.co.uk/[/url]$1 [R=301,L]
 

When you go to any m.  page  it says it is in a "re direction loop".

Any ideas anyone?

Edited by WiseWebmaster

Share this post


Link to post
Share on other sites

It would appear that I had an ! and a missing backslash in my code.

It works Ok now.  Thanks WW.

RewriteCond %{HTTP_HOST} [color=#ff0000][b]![/b][/color]^www\.m\.brand-newhomes\.co\.uk [NC]          [color=#ff0000][b]![/b][/color] not required
RewriteRule ^(.*)$ [url=http://m.brand-newhomes.co.uk/]http://m[b][color=#ff0000]\[/color][/b].brand-newhomes.co.uk/[/url]$1 [L,R=301]                    [b][color=#ff0000] \[/color][/b]  missing
Isn't it funny that a tired webmaster can never see the error and spend hours going around the same loop.

But come back to it fresh the next day and it takes a minute or tow to fix.

Edited by WiseWebmaster

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×