Forum Moderators: phranque

Message Too Old, No Replies

newbie to htaccess

Problem with http://domain redirecting to http://www

         

aaronjf

3:27 am on Sep 21, 2006 (gmt 0)

10+ Year Member



I was on a forum for working with mod_rewrites and being a newbie to htaccess I started at the begining. After I read the primars I followed a link off the the Apache site where it went into detail about redirecting requests for http://example.com to http://www.example.com using

RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) [fully.qualified.domain.name...] [L,R]

Thinking this would be a good way to get my feet wet I took the example and changed it to what I thought it was meant to be so I did

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

Loaded into my htacess file went to http://example.com and nothing happened. I was not redirected to http://www.example.com (of course using my domain instead of example.com)

Yes I started with:
Options +FollowSymLinks
RewriteEngine on

What did I do wrong?

jdMorgan

12:29 pm on Sep 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In a per-directory .htaccess context, the URL-paths tested by RewriteRule are stripped of the path to the current directory. Since the current directory for this .htaccess file is "/", that slash will be stripped from the path seen by your rule. Therefore, your RewriteRule pattern will never match, and the rule won't ever be invoked.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim