Urgent Mod_Rewrite Help

Discussion in 'Apache' started by Fahd, Sep 11, 2007.

Thread Status:
Not open for further replies.
  1. #1
    I have a block of rewrite rules. How do I make it so that these rewrite rules go into effect only if the actual html files don't exist.

    I tried putting...

    
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    
    Code (markup):
    ...at the top of the .htaccess file but it doesn't seem to be working. Even if the .html file requested exists it uses one of the redirect rules.

    I have narrowed the problem down to one or both of these rewrite rules for support for custom pages.

    RewriteRule ^(.+).(htm|html)/?$ /page.php?id=$1 [NC]
    RewriteRule ^(.+).(htm|html)/?$ /page.php?id=$1 [NC]
    Code (markup):
    How can I fix this?

    Thanks for any help in advance! :)
     
    Fahd, Sep 11, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Your RewriteCond statements are only affecting the first rule after them (this can be worked around with skipping but doesn't seem to be needed in your case). Also, you shouldn't be using OR, as every request is either "not a file" OR "not a directory", sorry if that is hard to understand. Also, both your RewriteRule's are the same.

    Here is the new code, not the omission or OR which ends up being an AND, i.e. if request is "not a file" AND "not a directory"

    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+).html?/?$ page.php?id=$1 [NC,L]
     
    krt, Sep 11, 2007 IP
Thread Status:
Not open for further replies.