Search code examples
apachemod-rewritedynamic-url

Help with mod_rewrite rule for dynamic url


Ugh.. mod_rewrite makes me feel stupid. I just haven't wrapped my brain around it yet. :/

I have this url:

http://example.com/a/name/

...that I want to point here:

http://example.com/a/index.php?id=name

...where name is what is getting passed to index.php as the id argument.

Anything I've tried results in either a 404 or a 500.. :(


Solution

  • To start you off:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !index.php
    RewriteRule ^/?a/([^/]+)/?$ /a/index.php?id=$1 [QSA,L]
    

    If one rewrite tutorial doesn't work for you, try another.

    Edit: excluded index.php as per Gumbo's suggestion