I've got a redirect I want to do using web.config on an IIS 7.5 server running Windows Server 2008 R2. I'd like to simply make a shortcut URL for another URL with a very long query string:
www.example.com/redirect -> www.example.com/long_url.aspx?key1=value1&key2=value2
When I add the following rewrite rule to web.config though, it gives a 500 Internal Server Error:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="^redirect$" stopProcessing="true">
<match url="^redirect$" />
<action type="Redirect" url="/long_url.aspx?key1=value1&key2=value2" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
What do I need to change to get this to work?
When adding a query string in the action of a rewrite rule, you've got to escape all the "?" and "&" characters in the URL.
The following code will work: