I'm creating an outbound rule that captures out query string parameters. I'm getting a very weird result where the url-encoded & (ampersand) is prepending amp; to the beginning of the next capture group. I can't figure out why. The purpose of that
part of my rule is to eat the extra ampersand between query string variables.
As you can see, the ampersand is detected correctly, but the "amp;" part of the url-encoded string is being prepended to the next capture group. Why is that happened and how can I fix this?
Escaping does not help. I still get erroneous "amp;" appended into the capture. It's important to note that URL-encoding the rules is normal in the web.config. If I just do \& (without the "amp;" part it will generate a 500 server error due to bad web.config
formatting.
thx1200
2 Posts
Outbound rule: & not being captured correctly
Apr 21, 2012 02:17 AM|LINK
I'm creating an outbound rule that captures out query string parameters. I'm getting a very weird result where the url-encoded & (ampersand) is prepending amp; to the beginning of the next capture group. I can't figure out why. The purpose of that part of my rule is to eat the extra ampersand between query string variables.
My rule looks like:
<rule name="Forums URL Rewrite" preCondition="HTML">
<match filterByTags="A, Form, Input" pattern="^/Default.aspx\?(.*)(?:tabid=92&?)(.*)" />
<action type="Rewrite" value="/Forums/Default.aspx?{R:1}{R:2}" />
</rule>
<preConditions>
<preCondition name="HTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="text/html" />
</preCondition>
</preConditions>
The input URL looks like this: http://www.contoso.com/Default.aspx?tabid=92&g=admin
The written URL looks like this: http://www.contoso.com/Forums/Default.aspx?amp;g=admin
The output SHOULD look like: http://www.contoso.com/Forums/Default.aspx?g=admin
As you can see, the ampersand is detected correctly, but the "amp;" part of the url-encoded string is being prepended to the next capture group. Why is that happened and how can I fix this?
jeff@zina.co...
3379 Posts
MVP
Moderator
Re: Outbound rule: & not being captured correctly
Apr 23, 2012 05:40 PM|LINK
Have you tried escaping the ampersand by using \& in the RegEx expression? Something like:
<match filterByTags="A, Form, Input" pattern="^/Default.aspx\?(.*)(?:tabid=92\&?)(.*)" />
Or is it a double backslash? Never can remember until one doesn't work and I try the other. :)
Jeff
thx1200
2 Posts
Re: Outbound rule: & not being captured correctly
Apr 24, 2012 01:32 AM|LINK