I have some legacy URLs that I need to redirect that have a tilde (~) as part of the URL. I'm having some issues getting the IIS Rewrite rules to work.
OLD URL: http://www.example.com/~/media/something/whatever.pdf
Need it to redirect to: /whatever
I have the following rules in place:
Web.Config
<rewrite>
<rewriteMaps configSource="RewriteMaps.config" />
<rules configSource="RewriteRules.config" />
</rewrite>
RewriteMaps.config
<rewriteMaps>
<rewriteMap name="Legacy URLS">
<!--DOES NOT WORK-->
<add key="~/media/something/whatever.pdf" value="/whatever" />
<!--WORKS-->
<add key="/testing123" value="/whatever" />
</rewriteMap>
</rewriteMaps>
RewriteRules.config
<rules>
<rule name="Redirect rule1 for Legacy URLS" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{Legacy URLS:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
I'm thinking you must need to escape the tilde, perhaps HTML Encode: ~
( http://www.ascii.cl/htmlcodes.htm ) or URL Encode.
Otherwise it must be interpreting ~ differently, a la application home.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.