【问题标题】:Remove Subdomain from URL in IIS or ASP.net MVC or haproxy从 IIS 或 ASP.net MVC 或 haproxy 中的 URL 中删除子域
【发布时间】:2015-04-24 00:52:01
【问题描述】:

是否可以从 URL 中删除子域(或基本上将其视为 www)?

示例: subdomain.domain.com/specific/link/forsubdomain -> domain.com/specific/link/forsubdomain

并且不让它指向主域并返回 404 错误, 例子: domain.com/specific/link/forsubdomain -> 返回 404,因为它只存在于子域中。

如果它也可以在 Haproxy 中做某事,或者在 ASP.net MVC 路由表修改中伪装 URL,我对它开放。

不仅仅是 IIS 配置。

只是想知道是否可以按照我的描述更改 URL 并使其仍然指向子域站点。

【问题讨论】:

    标签: asp.net-mvc iis web-config subdomain haproxy


    【解决方案1】:

    如果我正确理解您的问题,您指的是规范网址。

    在 IIS 中,您可以使用 URL Rewrite,这是一个您可以手动安装或通过 Web 平台安装程序(如果尚未安装)安装的模块。

    这允许您创建一个 url 重写规则,您可以为每个站点配置该规则,类似于:

    <rule name=”Redirect URL to WWW version”
        stopProcessing=”true”>
    <match url=”.*” />
    <conditions>
        <add input=”{HTTP_HOST}” pattern=”^example.com$” />
    </conditions>
    <action type=”Redirect” url=”http://www.example.com/{R:0}”
        redirectType=”Permanent” />
    </rule>
    

    您可以手动将规则添加到站点的 web.config 文件或使用 IIS 站点管理器工具中的 GUI。

    有很多 reference 以及来自 Microsoft 和众多博主的教程。

    一个example of a complete web.config 只是在做这种类型的重定向。

    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="WWW Redirect" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^contoso.com$" />
                    </conditions>
                    <action type="Redirect" url="http://www.contoso.com/{R:0}" redirectType="Permanent" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    【讨论】:

    • 如果 URL 是:tomatoso.com 并让它删除“tomatoes”并成为 contoso.com,但仍然指向子域,这是否也有效?
    • 您的意思是,如果有人输入了tomatoso.contoso.com,您仍然希望它返回到www.tomatoes.contoso.com?如果是这样,您只需要使规则更具体,以在条件和操作部分中包含子域。
    • 我的意思是,如果有人键入 tomatoes.contoso.com,它将被屏蔽、伪装或重写为 contoso.com。然而仍然指向子域而不是主域。这可能吗?
    • 抱歉回复延迟。是的,如果您想保留原始 url 的显示,您可以使用“重写”而不是“重定向”的操作类型。如果您进行了更改,也请删除 redirectType。
    猜你喜欢
    • 2018-09-07
    • 2015-07-20
    • 2017-09-20
    • 2017-01-15
    • 2012-04-14
    • 2013-12-08
    • 1970-01-01
    • 2012-12-11
    • 1970-01-01
    相关资源
    最近更新 更多