Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override an IIS rewrite rule for child site?

Tags:

iis

rewrite

I wanted to force all inbound connections to revert to HTTPS for my site. Searching StackOverflow.com for an answer yielded the following code:

<rewrite>
    <rules>
        <rule name="Redirect to HTTPS" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
        </rule>
     </rules>
</rewrite>

This works great. Now everyone coming in to http://mySite.com is redirected to https://mySite.com.

mySite.com has a sub-application which is accessed at mySite.com/ajax/ . I don't want inbound connections to this sub-application to be subject to the rewrite; The original protocol (http or https) that the user specifies should be maintained when connecting to the /ajax sub-application. What shall I place in this child application's web.config file to negate the rewrite that takes place at the parent level?

(The reason I want the /ajax child site to be exempt from the https rewrite is because it may be accessed from third-party HTTP-based web pages. If the third-party page that's making the call to /ajax is HTTP (not HTTPS), then I want to retain that HTTP'ness when the call is made.)

like image 988
Chad Decker Avatar asked Oct 12 '12 01:10

Chad Decker


People also ask

How do I disable URL Rewrite in IIS?

Open Internet Information Services (IIS) Manager > Servername > Sites > example.com > URL rewrite. Select each rewrite rule and disable them by clicking on Disable Rule.

Where are IIS rewrite rules stored?

When done on the server level it is saved in the ApplicationHost. config file. You can also define it on the folder level, it that case it is saved in a web. config file inside that folder.


1 Answers

The following web.config snippet should do what you want. It removes all rewrite rules for this application.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <!-- Insert rules for this application (if any) **below** the "clear" -->
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
like image 56
Moshe Katz Avatar answered Oct 23 '22 20:10

Moshe Katz