Hi all.

I'm using this rewrite rules to convert the querys to http://example.com to http://www.example.com

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

The problem comes when someone tries to access directly:
http://example.com/2006/06/some_article
because instead of rewriting it to:
http://www.example.com/2006/06/some_article
the rewrite goes to:
http://www.example.com

Does anyone know how to avoid this behavior?

Thanks a lot!
S.

Comments

adobo’s picture

Hello, try this:

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

You forgot the requested URL in the rewrite rule :)

elhombresinatributos’s picture

As you say, I forgot (not really because I didn't knew it existed) the requested URL.

Thanks, it works perfectly now.