简体   繁体   English

从IIS或ASP.net MVC或haproxy中的URL删除子域

[英]Remove Subdomain from URL in IIS or ASP.net MVC or haproxy

Is it possible to remove a subdomain (or basically treat it like www) from the URL? 是否可以从URL中删除子域(或基本上像www一样对待它)?

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

and not have it point to the primary domain and return a 404 error, example: domain.com/specific/link/forsubdomain -> return a 404 because it only exists in the subdomain. 并且没有将其指向主域并返回404错误,例如:domain.com/specific/link/forsubdomain->返回404,因为它仅存在于子域中。

If it's possible to do something in Haproxy as well Or disguising URLs in ASP.net MVC Route table modifications im open to it. 如果也可以在Haproxy中做某事,或者在ASP.net MVC中伪装URL,则可以对路由表进行修改,以免打开。

Not just IIS configuration. 不只是IIS配置。

Just wanted to know if it's possible to change the URL as i described and still have it point to the subdomain site. 只是想知道是否有可能像我描述的那样更改URL,并且仍然将其指向子域站点。

If I understand your question correctly you are refering to canonical URLs. 如果我正确理解了您的问题,则表示您使用的是规范网址。

Within IIS you can use URL Rewrite , which is a module you can install manually or via the Web Platform Installer (if it's not already installed). 在IIS中,您可以使用URL Rewrite ,该模块可以手动安装,也可以通过Web Platform Installer(如果尚未安装)安装。

This allows you to create a url rewrite rule which you can configure per site, something along the lines of; 这样,您就可以创建一个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>

You can add the rules manually to the site's web.config file or use a GUI within the IIS site manager tool. 您可以将规则手动添加到站点的web.config文件中,或使用IIS站点管理器工具中的GUI。

There's a lot of reference and a number of tutorials available from Microsoft and numerous bloggers. Microsoft和众多博客作者提供了大量参考资料和大量教程。

An example of a complete web.config just doing this type of redirect. 仅执行这种重定向的完整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>

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

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