Checking for an empty QUERY_STRING ?
4 posts
• Page 1 of 1
Checking for an empty QUERY_STRING ?
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:
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
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
Re: Checking for an empty QUERY_STRING ?
Hello, Adam
First, please clarify if you are using v2 or v3.
The rule for v2 should look like:
RewriteRule ([^&]+)&(.+) $1\?$2 [RP]
First, please clarify if you are using v2 or v3.
The rule for v2 should look like:
RewriteRule ([^&]+)&(.+) $1\?$2 [RP]
Re: Checking for an empty QUERY_STRING ?
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:
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:
then it seems to work correctly. Which seems to suggest the RewriteCond is not required ?
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 ?
Re: Checking for an empty QUERY_STRING ?
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.
You don't need to use RewriteCond %{QUERY_STRING} in ISAPI_Rewrite 2, it's only for v3 syntax.
Your rule looks just fine.
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests