简体   繁体   English

URL重写到子域

[英]URL Rewrite to subdomain

For a URL rewrite I need support.mydomain.com to point to mydomain.com/support.对于 URL 重写,我需要 support.mydomain.com 指向 mydomain.com/support。 What I have is rewriting to support.mydomain.com/support.我所拥有的是重写 support.mydomain.com/support。

I've tried 2 different variations, but no luck.我尝试了 2 种不同的变体,但没有运气。 Any help is greatly appreciated.任何帮助是极大的赞赏。

Version 1版本 1

<rewrite>
    <rules>
        <rule name="rewrite support" enabled="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^support.mydomain.com$" />
        </conditions>
        <action type="Rewrite" url="\support\{R:0}" />
        </rule>
    </rules>
</rewrite>

Version 2版本 2

<rule name="Support Rule" stopProcessing="false">
    <match url="(.*)" />
     <conditions>
         <add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.mydomain\.com$" />
     </conditions>
     <action type="Rewrite" url="{C:1}/{R:1}" />
</rule>

I was able to find this post by Scott Forsyth that got this working for me.我能够找到 Scott Forsyth 的这篇文章,它对我有用。

As he states in the article "This will redirect the link http://anything_except_www.domain.com to http://domain.com/anything_except_www."正如他在文章中所说:“这会将链接 http://anything_except_www.domain.com 重定向到 http://domain.com/anything_except_www。”

<rewrite>
    <rules>
        <rule name="CName to URL" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^(?!www)(.*)\.domain\.com$" />
            </conditions>
            <action type="Redirect" url="http://domain.com/{C:1}/" />
        </rule> 
    </rules>
</rewrite>

Hope this helps someone!希望这可以帮助某人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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