Non-WWW to WWW in specific directory

Discussion in 'Water Cooler' started by Nick, Mar 12, 2009.

  1. Nick

    Nick Regular Member

    Joined:
    Jul 27, 2008
    Messages:
    7,441
    Likes Received:
    218
    I have the rewrite for visitors who go to mysite.com to be redirected to www.mysite.com and it works fine.

    The problem is that I cannot get this to work for a specific directory.

    I want users who navigate to mysite.com/directory to be redirected to www.mysite.com/directory.

    This is what I have in that specific directory's .htaccess (not my root's .htaccess):

    Code:
    # Non-www to WWW
    RewriteCond %{HTTP_HOST} !^www\.mysite\.com\.directory[NC]
    RewriteRule (.*) http://www.mysite.com/directory/$1 [R=301,L]
    And for some reason, this results in a browser error telling me it is resulting in an infinite loop that will never end.

    Why is that and how do I fix it?

    Thanks :)
     
  2. Webmist

    Webmist Champion

    Joined:
    Jan 30, 2008
    Messages:
    305
    Likes Received:
    18
    Location:
    US
    First Name:
    Jen
  3. Demo

    Demo Regular Member

    Joined:
    Jun 9, 2009
    Messages:
    172
    Likes Received:
    6
    Location:
    Europe
    First Name:
    Demo
    I am currently using this
    Code:
    # WWW-ONLY #
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
    site.com is easily redirected to www.site.com

    The problem is that other directories aren't redirected. Exp. site.com/forum/ to www.site.com/forum/. How can this be done? I tried %{REQUEST_URI}, but to no avail...
     

Share This Page