简体   繁体   中英

iis redirect subdomain to subfolder on same subdomain

I have an IIS site and Im trying to use ReWrite 2.0 to redirect a particular subdomain to a sub folder. Within my IIS site I have it binded to two different domains:

  • one.example.com
  • two.example.com

When people visit one.example.com I want it to do nothing. When people visit http://two.example.com I want them to be redirected to http://two.example.com/subfolder .

Thanks for your help.

You need to add a match condition for the HTTP_HOST

<system.webServer>
    <rewrite>
        <rules>
            <rule name="two.example.com Redirect" stopProcessing="false">
                <match url="^\/?$" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern=".*two\.example\.com.*" />
                </conditions>
                <action type="Redirect" redirectType="Found" url="http://two.example.com/subfolder/{R:0}" />
            </rule>
       </rules>
    </rewrite>
</system.webServer>

Here's a decent overall reference for the module: http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

A very late answer, but hopefully it helps someone.

I presume you are using II7 or higher ?

IIS has a simple HTTP redirect function which is available per site listed in IIS.

Make sure you are in features view. Click on the site you want to redirect (In your case its http://two.example.com )

You should see this. Double click on HTTP Redirect IIS视图

The you should see this. Enter your Redirect URL here (In your case its http://two.example.com/subfolder )

HTTP重定向视图

This existing question should solve your issue

<system.webServer>
<rewrite>
    <rules>
        <rule name="Root Hit Redirect" stopProcessing="true">
            <match url="^$" />
            <action type="Redirect" url="/menu_1/MainScreen.aspx" />
        </rule>
    </rules>
</rewrite>
</system.webServer>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM