Reputation: 1073
I'm trying to create a rewrite rule to redirect to a URL based on a conidtion.
I have had a look on-line for similar questions but am finding myself confused.
My rewrite rule looks like follows:
RewriteRule ^rates/(\w+)/?$ http://www.url.co.uk/rates/result.php?quotenum=$1 [R,L]
For example, this will redirect any combination of characters after the URL
www.url.co.uk/rates/1234
to
www.url.co.uk/rates/result.php?quotenum=1234
I am creating an admin page as well which will sit at the URL:
www.url.co.uk/rates/admin
How do I modify my rewrite rule to prevent the redirection of the URL to
www.url.co.uk/rates/result.php?quotenum=admin
When the URL is equal to
www.url.co.uk/rates/admin
Upvotes: 1
Views: 652
Reputation: 785146
This should work:
RewriteRule ^rates/((?!admin/?$)\w+)/?$ http://www.url.co.uk/rates/result.php?quotenum=$1 [R,L,NC]
(?!admin/?$)
is a negative lookahead that will not match given regex if URI is /rates/admin
OR /rates/admin
Upvotes: 1