Help with .htaccess 301 Redirect

Discussion in 'Site & Server Administration' started by iBBnet, Jun 8, 2008.

  1. #1
    This one's confusing me, and I hope someone can clarify this for me.

    I'm trying to have all non-www pages in a subdirectory redirect to a www option:

    http://domain.com/subdirectory/pagename.html   REDIRECT TO
    http://www.domain.com/subdirectory.pagename.html
    
    where pagename.html = whatever name each page may be in that subdirectory
    Code (markup):
    What's the htaccess code to incorporate?

    Thanks for the help guys!
     
    iBBnet, Jun 8, 2008 IP
  2. petrh

    petrh Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hello iBBnet,

    it's easy, try this code:

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

    Petr
     
    petrh, Jun 11, 2008 IP