I have a ReWrite Map and I would like to append any query parameters in the requested URL to the rewritten URL.
For instance:
My web.config is:
[...]
<rules>
<clear />
<rule name="Rewrite rule1 for SiteMapEngine">
<match url=".*" />
<conditions>
<add input="{SiteMapEngine:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="true" />
</rule>
</rules>
[...]
I'll be damned if I can find a reference for this, but it's my understanding that in some versions of IIS {REQUEST_URI} comes back without it's query string, and will be empty entirely if rewriting is enabled.
You should be able to use {PATH_INFO} instead.
This bug report (against Drupal!) is the issue you're describing, I think: http://drupal.org/node/298016
There's a hotfix from Microsoft, but I haven't tried it: http://support.microsoft.com/kb/954946
Short answer:
Use PATH_INFO server variable instead of REQUEST_URI, as you do not want to include the query string in the matching.
Full explanation:
This has caught me out before - basically it is a subtlety of using Rewrite Maps in the IIS URL Rewrite Module.
In your case, SiteMapEngine will be a static key-value list of URLs:
<rewrite>
<rewriteMaps>
<rewriteMap name="SiteMapEngine" defaultValue="">
<add key="/page/abc/" value="/index.cfm?page=abc" />
...
</rewriteMap>
</rewriteMaps>
...
</rewrite>
The {SiteMapEngine:{REQUEST_URI}} condition in your rule checks whether there is a key in this rewrite map matching the REQUEST_URI server variable:
{REQUEST_URI} = /page/abc/?param1=111
Notice that this variable includes the query string - it therefore fails to find a matching key.
Instead, use the PATH_INFO server variable, which is the equivalent of REQUEST_URI but without the query string:
{PATH_INFO} = /page/abc/
So the correct rule is:
<rule name="Rewrite rule1 for SiteMapEngine">
<match url=".*" />
<conditions>
<add input="{SiteMapEngine:{PATH_INFO}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" />
</rule>
Here is my rule. It seems to work as expected:
<rule name="Insert index.cfm" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.cfm/{PATH_INFO}" appendQueryString="true" />
</rule>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With