2

I am having issues redirecting non-www to www via .htaccess. Non-www links are not redirecting to www when directly access non-www.host/request_params. For example I want to redirect examplehost.com/param1/param2 to www.examplehost.com/param1/param2, but the url examplehost.com/param1/param2 redirects to www.examplehost.com/index.php.

I am using the code below for redirecting all non-www to www links in .htaccess

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

Please give me suggestion to resolve this issue.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • Your directives could be simplified, but they look as if they should work. Do you have other directives in your .htaccess file that are perhaps conflicting? Add the contents of your .htaccess file if you do. – MrWhite Mar 23 '15 at 14:18
  • What if you replace `[R=301,L]` by `[R=301,L,QSA]` ? – ben Mar 23 '15 at 14:26
  • @ben The `QSA` flag would only be required if you were explicitly appending a query string in the `RewriteRule` substitution. But there is no query string in the example anyway. – MrWhite Mar 23 '15 at 14:35
  • @w3d Thanks for the info, i didn't know that obviously – ben Mar 23 '15 at 14:58

0 Answers0