1

I want to redirect from http://domain.com/folder/ to http://www.domain.com/folder/

I have tried below code

RewriteCond %{HTTP_HOST} ^domain.com [nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

AND

RewriteCond %{HTTP_HOST} domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/folder/index.html [R=301,NC]

It redirects to http://domain.com/ to http://www.domain.com/ Not http://domain.com/folder/ to http://www.domain.com/folder/

also it redirect to http://domain.com/folder/ to http://www.domain.com/ But not to http://www.domain.com/folder/

Please suggest what issue and help to solve it. Thanks.

Sandeep
  • 956
  • 2
  • 9
  • 19
  • @crypticツ: I need redirection to non www to www within subfolder. Above code work for only main domain not for sub folders. :P – Sandeep Apr 12 '14 at 10:26
  • @crypticツ: You don't understand difference between Apache and .htaccess code? I don't have rights to edit Apache but I can edit .htaccess. – Sandeep Apr 12 '14 at 10:33
  • Did you bother to look at the other answers on that page? My guess is you didn't. Because you make no effort in looking up the solution to something that has been asked many times before. – kittycat Apr 12 '14 at 22:57

1 Answers1

3

This should work:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} ^/folder/
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

It should only redirect http://domain.com/folder/ to http://www.domain.com/folder/

Howli
  • 12,291
  • 19
  • 47
  • 72