Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule: Unable to redirect from 'foo.com' to 'www.foo.com'

using htaccess

         

guarriman

8:38 am on Sep 11, 2007 (gmt 0)

10+ Year Member



Hi.

This is my piece of code within my '.htaccess' file:
---------------
RewriteEngine On
RewriteCond %{HTTP_HOST} [foo.com...]
RewriteRule ^/(.*) [foo.com...] [L,R=301]
-----------------

This must work, right?

I'm not able to configure it in order to work :(

wheelie34

9:14 am on Sep 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this

RewriteEngine on

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

It works for me

g1smd

11:33 am on Sep 11, 2007 (gmt 0)

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



The HOST should include only the name, not the http:// preamble. The added NC makes it case insensitive.

If the code is going in .htaccess then RewriteRule cannot see the leading / on the requested path. If the code is going in httpd.conf, then it can see the leading / there.

Escape the literal period in the HOST part. The example in the post immediately above, is all good.