mod_rewrite - my regex is half right... or half wrong!

Discussion in 'Apache' started by spuntotheratboy, Mar 26, 2010.

  1. #1
    Hello,

    I'm trying to use mod_rewrite for friendly URLs - I've got it half working, and I've read so much documentation it's coming out of my ears :-/

    So here's the deal - I want URLs in either of these forms:

    http://domain/foo?querystring
    http://domain/foo/?querystring

    to be silently converted to

    http://domain/?unique_name=foo&querystring

    My current .htaccess works fine for the first of these, but fails on the second, and I can't trace the problem. I'd be really grateful if someone could point out my mistake. The file looks like this:

          1 #ErrorDocument 404 /index.php
          2 
          3 RewriteEngine  on
          4 #RewriteBase /
          5 
          6 RewriteCond    %{REQUEST_URI} ^/[^/]+/
          7 RewriteRule    ^([^/]).*$     $1 [QSA]
          8 
          9 RewriteCond    %{REQUEST_URI} !^/index\.
         10 #RewriteCond   %{REQUEST_URI} ^/[^/]+$
         11 RewriteCond    %{REQUEST_FILENAME} !-f
         12 RewriteCond    %{REQUEST_FILENAME} !-d
         13 RewriteCond    %{REQUEST_FILENAME} !-l
         14 RewriteRule    ^([^/]+) /?unique_name=$1 [L,QSA]
    Code (markup):
    I've tried a lot of stuff...

    Thanks very very much!

    Ben
     
    spuntotheratboy, Mar 26, 2010 IP