Forum Moderators: phranque

Message Too Old, No Replies

Redirecting to www subdomain

         

WebWalla

7:56 am on Nov 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Will this code redirect all requests for example.com/anyurl to www.example.com/anyurl?

RewriteCond %{HTTP_HOST} example.com$ [NC]
RewriteRule ^(.*) [example.com...] [R=301,L]

Is there any simpler or better way of doing it?

Thanks.

jdMorgan

3:31 pm on Nov 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, but it will also redirect from www.example.com to www.example.com - In other words, it will loop forever.

You must start-anchor the example.com pattern in your RewriteRule to prevent this. Also, I suggest you do *not* end-anchor your pattern, and that you escape your literal periods with "\".


RewriteCond %{HTTP_HOST} [b]^e[/b]xampl[b]e\.c[/b]o[b]m[/b] [NC]

Jim