Reputation: 767
How do I rewrite everything after the question mark (?) as one parameter?
For example, I have a url as: http://www.example.com?abcdefg/test/module?wiating4request
Notice after the first question mark we have another in the query string. I basically need to post to that url and I cannot modify the url so I need to make do with what is provided.
I saw something similar here: How can I use mod_rewrite to remove everything after the ? (question mark) in a URL?
Keep in mind this is for IIS 7.
Any ideas?
Upvotes: 1
Views: 569
Reputation: 6138
It's possible to do this with a rewrite rule in case you only want to match URL's with just one question mark too many, like your example. You can then use this rule:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Clean extra question mark from query string" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="^(.+?)(\?(.+))*$" />
</conditions>
<action type="Rewrite" url="/{URL}?{C:1}&{C:3}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If you want to match an unlimited number of too many question marks I think you will need to revert to a custom rewrite provider as detailed in the linked article. You might then end up with something like:
<rule name="Clean extra question mark from query string" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="^$" negate="true" />
</conditions>
<action type="Rewrite" url="/{URL}?{ReplaceProvider:{QUERY_STRING}}" appendQueryString="false" />
</rule>
Upvotes: 1