简体   繁体   中英

Redirect subdomain in IIS via web.config file

Looking to redirect old subdomain back to the primary domain name (remove the subdomain if it's seen) in the web.config file for IIS.

For example, preview.mysite.com redirects to mysite.com

The rule I've tried is this:

<rule name="Redirect away from Preview" enabled="true" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="preview.mysite.com" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>

It stops preview subdomain from loading, but shows error message instead of doing a redirect

This page isn't working preview.mysite.com redirected you too many times.

What can I do to correct the redirect rule to reroute any preview subdomain back to the base domain?

Got it fixed.Had to hardcode the redirect url and that fixed the looping issue, now redirects to the main domain:

<rule name="Redirect away from Preview" enabled="true" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="preview.mysite.com" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="https://example.com" redirectType="Permanent" appendQueryString="false" />
</rule>

Hope this helps someone else. (Note: stackoverflow would not allow me to put mysite for the url so it shows example.com instead)

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