htaccess - problem with 'dots' in url variables

Discussion in 'Apache' started by Kerosene, Dec 18, 2007.

  1. #1
    I have a form that redirects users to a url depending on the word they enter in a form.

    1. A user enters 'banana' in the form and hits submit
    2. They're taken to domain.com/banana in their browser
    3. Which is rewritten to domain.com/index.php?s=banana by htacess

    The problem is when somebody enters a word with a dot, like 'banana.apple'. The user is redirected to domain.com/banana.apple and gets a 404.

    If I manually enter domain.com/index.php?s=banana.apple then everything works fine.

    How can I fix this?

    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d 
    RewriteRule ^([^/.]+)/?$ index.php?s=$1 [QSA,L]
    Code (markup):
     
    Kerosene, Dec 18, 2007 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !\.(html?|php\d?)$
    RewriteRule ^([^/]+)/?$ index.php?s=$1 [QSA,L]
    Code (markup):
     
    joebert, Dec 19, 2007 IP
    Kerosene likes this.
  3. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #3
    Thanks! It looks so simple when someone else does it :p

    +rep :)
     
    Kerosene, Dec 20, 2007 IP