.htaccess problem! Please help.

Discussion in 'Apache' started by lslars31, May 18, 2007.

  1. #1
    My Problem: I want anything.html to be directed to page.php?nicename=anything

    The problem is that when I use this line of code:

    RewriteRule ^(.*).html$ page.php?nicename=$1 [L]

    It also screws up every html page on my site including my index.html and any other .html files in the other directories.

    How do I get it to work without affecting my index.html file or files in other directories?

    I know there must be some conditional rule I can apply, but I just don't know which one to use.
     
    lslars31, May 18, 2007 IP
  2. cyanide

    cyanide Peon

    Messages:
    483
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change the file from index.html to index.php ;)
     
    cyanide, May 18, 2007 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #3
    Chage it to a static looking extention that you don't use, like .shtml or .htm. .php would just kill it, making apache not know what to spit out...and .php isn't as search engine friendly.
     
    Nintendo, May 18, 2007 IP
  4. lslars31

    lslars31 Peon

    Messages:
    260
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That's kind of obvious... what I want is to have the same file extension for all of my pages.

    What? That's the whole idea, I am trying to make my page.php?nicename=page into something like "page.html"
     
    lslars31, May 19, 2007 IP
  5. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Add a condition that checks if the file exists - then only rewrite if the requested .html file is not a real .html page:
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule ^(.*).html$ page.php?nicename=$1 [L]
    Code (markup):
     
    rodney88, May 19, 2007 IP
  6. lslars31

    lslars31 Peon

    Messages:
    260
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Wow thanks that helped a lot! The only problem now is that it is still affecting an index file in another directory because it isn't "real"

    Is there a conditional that will only apply the rule in my "/" base directory?
     
    lslars31, May 19, 2007 IP
  7. lemaitre

    lemaitre Peon

    Messages:
    61
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I think this will do the trick:

    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule ^([^/]*).html$ page.php?nicename=$1 [L]
    Code (markup):
     
    lemaitre, May 19, 2007 IP
  8. lslars31

    lslars31 Peon

    Messages:
    260
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Now I am getting an internal server error. hmmm.
     
    lslars31, May 19, 2007 IP
  9. lslars31

    lslars31 Peon

    Messages:
    260
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    got it! Thanks everyone so much! I just wish I knew what that meant...
     
    lslars31, May 19, 2007 IP
  10. lemaitre

    lemaitre Peon

    Messages:
    61
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    lemaitre, May 19, 2007 IP