Help with mod_rewrite rule for dynamic url
Uh .. mod_rewrite makes me feel stupid. I just haven't wound my brain yet.: /
I have this url:
http://example.com/a/name/
... what I want to point out here:
http://example.com/a/index.php?id=name
... where name
is what is passed in index.php
as an argument id
.
Everything I've tried results in either 404 or 500 .. :(
a source to share
To turn off:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^/?a/([^/]+)/?$ /a/index.php?id=$1 [QSA,L]
If rewriting the tutorial doesn't work for you, try another one .
Edit: Deleted index.php
as suggested by Gumbo
a source to share
If you want the trailing slash optional, you must exclude the file for which you are rewriting the request. Otherwise, you have a nice infinite recursion.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/a/index\.php$
RewriteRule ^/a/([^/]+)/?$ /a/index.php?id=$1 [L]
Here any query starting with /a/…
, but not /a/index.php
, rewritten to /a/index.php
.
But if the trailing slash is required, there is no need to exclude the target file:
RewriteEngine on
RewriteRule ^/a/([^/]+)/$ /a/index.php?id=$1 [L]
a source to share
I suggest you take a look at this url:
http://www.dracos.co.uk/code/apache-rewrite-problem/
The solutions presented will work, but there are explanations in the url, mainly regarding? and # in the URLs themselves.
a source to share