Rewrite Maps in IIS7 – Not redirecting

iis-7redirecturl-rewrite-module

I'm trying to use a separate config file, named "rewritemaps.config", that contains the URLs I want to redirect. The file is in the root directory (same place as the web.config). The format of the Redirects.config file I have is:

<rewriteMaps>
    <rewriteMap name="Redirects">
        <add key="aspx/drvmain.aspx"
             value="http://www.newdomain.com/folder2/page2.aspx" />
        <add key="aspx/jobs_AboutUs.aspx"
             value="http://www.newdomain.com/folder1/jobs.aspx" />
        <add key="aspx/page.aspx"
             value="http://www.newdomain.com/folder1/page2.aspx" />
    </rewriteMap>
</rewriteMaps>

In my web.config file, I have:

<system.webServer>
    <rewrite>
        <rewriteMaps configSource="rewritemaps.config" />
            <rules>
                <rule name="Redirect rules">
                    <match url=".*" />
                    <conditions>
                        <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
                    </conditions>
                    <action type="Redirect" redirectType="Permanent"
                            url="{C:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewriteMaps>
    </rewrite>
</system.webServer>

In the IIS Manager (which, yes, I have installed the URL Rewrite module), I've even gone and tested the rule and condition against one of my URLs in the redirects.config file and it says it works. But then when I try going to the URL in my browser, it doesn't redirect as I've specified. In the rewritemaps.config file, I've tried putting the full domain, and I've tried with a "/" before aspx. Nothing seems to work. I'm not sure what I'm missing here.

Best Answer

Well I got it working. Was something stupid. In the rewritemaps.config file, I needed "/"s before the key URL. I know I had tried that before, but I must have been missing something somewhere else at the time. Oh well. It works now.

Related Topic