user3081828
user3081828

Reputation: 11

RewriteCond to check if a specific Query String does not exist in the URL

Need help in writing a RewriteCond to check if a specific QueryString does not exist in the URL.

If a specific string "?nvi" does not exist then only should I redirect the URL.

Below Rule is what I have written but it does not work:-

RewriteCond %{QUERY_STRING} !(.*nvi.*) [NC]
RewriteRule . /index.php [L]

But the above rule fails even when the URL has string "?nvi" in the URL(www.text.com?svi).

Please help me write rewritecond which will redirect to a new URL only when the "?nvi" string does not exist in the requested URL.

Upvotes: 1

Views: 5357

Answers (1)

anubhava
anubhava

Reputation: 784928

Try this rule:

RewriteCond %{QUERY_STRING} !^nvi [NC]
RewriteRule ^ /index.php? [L]

? in the end will strip down existing query string.

Upvotes: 3

Related Questions