I’m writing a mod_rewrite rule and would like a hand making it do what I want.
Basically I want the following cases to work:
request | Redirect to
---------------------
cheese | /?page=cheese
abc123 | /?page=abc123
abc/def | /?page=abc/def
a/b/c/d | /?page=a/b/c/d
(Any alphanumeric plus . – / and _ redirected)
With two special cases:
request | Redirect to
------------------------
admin | don't redirect
media | don't redirect
With these two I don’t want any sub directories etc to redirect either.
I’ve got as far as:
RewriteRule ^([A-Za-z0-9-_]+)/$ /index.php?page=$1 [L]
But this only satisfies the top two tests.
Any ideas?
I would create a separate earlier rule (as Kobi also suggested) and use the
RewriteRule dash directiveto prevent substitution.(I wasn’t able to test this where I’m at right now, so you might need to edit this slightly – sorry .. but the idea should be clear)Tested on Apache 2.2
EDIT: Was able to try this out now – needed to add the [L] to make it work.
EDIT2: Realized I didn’t answer the full question, added rules for the rest of the stuff.