如何重定向任何子请求在asp.net中的主域名 [英] How to Redirect any subdomain request to main domain in asp.net
问题描述
我想为domain.com的所有子域名请求重定向到www.domain.com和用户只有进入到主域名,并点击链接,必须访问的网站的一部分,例如,如果用户直接输入下面地址中浏览器:
I'm trying to redirect all subdomain requests for domain.com to www.domain.com and user must access all part of website only by enter to main domain and click on links , for example if user directly enter following address in browser:
subdomain.domain.com
或
www.domain.com/post/showPost.aspx?pid=11
我想显示错误页面,然后重定向到www.domain.com
i want to show error page and then redirect to www.domain.com
我使用asp.net和IIS 7.5和Visual Studio 2010
i use asp.net and IIS 7.5 and visual studio 2010
感谢您。
推荐答案
使用URL重写模块可能是要走的路。尝试使用类似以下配置:
Using the URL Rewriting module could be the way to go. Try using configuration similar to the following:
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to WWW" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern=".*" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
这将不显示错误页面重定向。如果你想显示错误页面,那么你就需要重定向到一个页面,需要返回URL并执行客户端重定向到正确的地方。
This will redirect without showing an error page. If you want to show an error page then you'll need to redirect to a page that takes the return URL and does a client-side redirect to the right place.
由于@inspile说你将有麻烦做它的网站的子页面。您可以使用引荐,以确保它从主站点上的链接是做到这一点。再次URL重写模块是去这里的道路。
As @inspile says you're going to have trouble doing it for sub-pages of the site. You may be able to do it using the referer to make sure it's from a link on the main site. Again the URL Rewrite module is the way to go here.
干杯
这篇关于如何重定向任何子请求在asp.net中的主域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!