labr1005 labr1005 - 3 months ago 19
Apache Configuration Question

Multiple RewriteCond RegEx

So I have the followings urls

foo/
foo/abc/
foo/def/
foo/ghi/
foo/([a-zA-Z0-9\-]+)/


and I only want to rewrite the last one(s). The first four (path segments) are fixed.

if first path segment is "foo"
and we have a second path segment
and second path segment is not "abc"
and second path segment is not "def"
and second path segment is not "ghi"
then ^foo/([a-zA-Z0-9\-]+)/$ index.php?id=20&alias=$1 [L, QSA]

Answer

You can use a negative lookahead.

RewriteEngine On

RewriteRule ^foo/((?!abc|def|ghi)[a-z0-9-]+)/$ index.php?id=20&alias=$1 [L,QSA]