3
votes

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>
1
Is the tilde ~ really part of the URL (e.g. you actually have a /~ folder in your server) or is being used in ASP.Net (application) context (to refer to "application root")?EdSF
Unfortunately, for reasons beyond our control, it is part of the URL.Amir Setoudeh

1 Answers

0
votes

I'm thinking you must need to escape the tilde, perhaps HTML Encode: &#126;

( http://www.ascii.cl/htmlcodes.htm ) or URL Encode.

Otherwise it must be interpreting ~ differently, a la application home.