Small htaccess problem

Discussion in 'Apache' started by Machi, Aug 3, 2007.

  1. #1
    Hi, I'm using phpLinkBid and it has own htacces but I wanna add to this htaccess one rule which redirects from domain.com to www.domain.com

    This is my htaccess after added two lines to the end:
    # Enable mod_rewrite engine
    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) index.php
    
    RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
    Code (markup):
    It works but just for domain without any opened page, when I'm trying to open domain.com/anything.php it opens just www.domain.com/index.php

    Please how to get it work? thanks a lot...
     
    Machi, Aug 3, 2007 IP
  2. froggy

    froggy Member

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    RewriteCond %{HTTP_HOST} !www\.domain\.com$ [NC]
    RewriteRule ^/?(.*)$ http://www.domain.com/$1 [R=301,L]
     
    froggy, Aug 6, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    That won't make a difference froggy.

    domain.com/anything.php to www.domain.com/index.php is the correct behaviour as the first rule is redirecting everything to index.php

    i.e.:

    Request: domain.com/anything.php
    First rule: domain.com/index.php
    Second rule: www.domain.com/index.php
     
    krt, Aug 6, 2007 IP