Really simple mod_rewrite question

Discussion in 'Apache' started by Kerosene, Jan 17, 2007.

  1. #1
    Can somebody help me clean up my ugly php urls?
    It's probably pretty simple, but obviously not simple enough for me :eek:

    REWRITE
    www.domain.com/blue+cars (with or without trailing slash)
    TO
    www.domain.com/index.php?s=blue+cars


    The amount of words in the $s variable will vary, but probably won't ever be more than 5 separate words.
     
    Kerosene, Jan 17, 2007 IP
  2. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #2
    Try it: paste these lines in your .htaccess file :

    Options +FollowSymLinks

    RewriteEngine On
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d

    RewriteRule ^/([^/]+)/?$ index.php?s=$1 [QSA,L]
     
    YIAM, Jan 17, 2007 IP
  3. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #3
    Thanks, but it doesn't seem to work.
    I get a 404:

    The requested URL /blue+cars was not found on this server.
     
    Kerosene, Jan 17, 2007 IP
  4. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #4
    With a bit of cut and paste, I've got it to work.

    Slightly different to YIAMs suggestion (maybe it was typos?). But this works:
    RewriteRule ^([^/\.]+)/?$ index.php?s=$1 [QSA,L]

    It seems to work the same with or without the first two lines. Can someone tell me what they do? And if I need them or not.
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
     
    Kerosene, Jan 17, 2007 IP