View Full Version : .htaccess 301 redirect

08-06-2010, 12:56 AM

here is the code most of the SEO companies prefer to have so that users using the site without www should be redirected to www

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

but when a user tried to open up domain.com/blog he gets redirected to www.domain.com and not the /blog page he was suppose to be.

so, is there a way where we can use 301 redirect but also keep them landing to the url they entered???

Thanks in advance.

08-06-2010, 03:20 AM
Try this:

rewriterule ^(.*)$ http://www.domain.com/{request_uri} [r=301,nc]

Not sure if it will work, but I think it might...

EDIT: Actually, I think your problem may be that you need to escape the dots in the domain:

RewriteEngine on
RewriteCond %{http_host} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]

08-06-2010, 03:27 AM

any other guesses?

08-06-2010, 03:38 AM
You replied to my post quickly. Did you notice my edit? I added another option.

I'm only guessing based on my limited experience with .htaccess. I'm no expert with it either.

Maybe if you tried to combine the two methods above it would work.

Alternatively, there should be plenty of info on google about "htaccess www redirect" but I don't see any typos here, but maybe in comparing it to a tutorial you'd find it.

08-06-2010, 04:03 AM

sure.. Thanks.