Checking for an empty QUERY_STRING ?

ISAPI_Rewrite is a powerful URL manipulation engine based on regular expressions
User avatar
Posts: 3
Joined: 22 Feb 2013, 05:45

Checking for an empty QUERY_STRING ?

22 Feb 2013, 05:53

Hi all,

I am trying to write a rule whereby if a URL has an & character in it then it must also have a preceding question mark.

My current, non-working, attempt is:

Code: Select all
RewriteCond %{QUERY_STRING} ^$
RewriteRule (^[^\&]+)\&(.+) xxxxxxxxxxxxxxxx$1?$2 [RP,I,L]


Which, I thought, only does the rule if the query string is empty but it doesn't seem to work.

Has anyone got any ideas what the issue is with my RewriteCond ? Or maybe have a better solution for what I am trying to do ?

Regards,

Adam Brunt

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Checking for an empty QUERY_STRING ?

22 Feb 2013, 08:34

Hello, Adam

First, please clarify if you are using v2 or v3.

The rule for v2 should look like:

RewriteRule ([^&]+)&(.+) $1\?$2 [RP]

User avatar
Posts: 3
Joined: 22 Feb 2013, 05:45

Re: Checking for an empty QUERY_STRING ?

22 Feb 2013, 13:27

Hi Anton,

I can't be certain but the according to the documentation.html file in (C:\Program Files\Helicon\ISAPI_Rewrite\Help) it is "ISAPI_Rewrite 2".

So, should my rule be:

Code: Select all
RewriteCond %{QUERY_STRING} ^$
RewriteRule ([^&]+)&(.+) $1\?$2 [RP]


Or do I not need the RewriteCond ?

UPDATE: That seems to work but it also means that if there is already a ? in the URL then there will now be two. However, if I use:

Code: Select all
RewriteRule ([^&\?]+)&(.+) $1\?$2 [RP,I,L]


then it seems to work correctly. Which seems to suggest the RewriteCond is not required ?

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Checking for an empty QUERY_STRING ?

25 Feb 2013, 07:59

Hello,

You don't need to use RewriteCond %{QUERY_STRING} in ISAPI_Rewrite 2, it's only for v3 syntax.
Your rule looks just fine.

Return to ISAPI_Rewrite 2.x

Who is online

Users browsing this forum: No registered users and 8 guests