Search code examples
url-rewritingiis-7.5

IIS URL Re-write Redirect to base


I'm hoping you can help me, I'm close but failing at the last hurdle.

I'm trying to redirect part of my website to the home page if not browsed from certain IP's. However it is failing with the redirect.

Example:

Site url: www.mysite.com Restricted path: www.mysite.com/secure

When people browse, if they attempted to that is, to the /secure path I want the site to automatically re-direct to www.mysite.com

What's currently happening is they are getting forwarded on to www.mysite.com/www.mysite.com and I'm not sure why.

This is my URL Re-write rule:

<rewrite>
        <rules>
            <rule name="Lockdown" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{REMOTE_ADDR}" pattern="123.123.123.123" negate="true" />
                    <add input="{REMOTE_ADDR}" pattern="111.111.111.111" negate="true" />
                    <add input="{PATH_INFO}" pattern="^/secure(.*)" />
                </conditions>
                <action type="Redirect" url="http://{Host_Header}" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>

Any ideas why my Redirect should actually be?


Solution

  • For anyone who has a similar problem, the below rewrite rule resolved my issue. Effectively I took out the http:// aspect of the url, I'm not sure why it worked though.

    <rule name="Lockdown" stopProcessing="true">
      <match url=".*" />
      <conditions>
         <add input="{REMOTE_ADDR}" pattern="123.123.123.12" negate="true" />
         <add input="{REMOTE_ADDR}" pattern="111.222.33.45" negate="true" />
         <add input="{PATH_INFO}" pattern="^/secure(.*)" />
      </conditions>
      <action type="Redirect" url="/{Host_Header}" appendQueryString="false" />
    </rule>