我看到很多类似的问题都是用乱码写的,我不明白:
- 使用 .htaccess 将非 www URL 重定向到 www https://stackoverflow.com/q/50931/153923
- 将不带 www 的 URL 重定向到 www https://stackoverflow.com/q/2272159/153923
- 将非 WWW URL 重定向到 WWW URL https://stackoverflow.com/q/7228653/153923
- 将 url 重写为非 www 多个站点 https://stackoverflow.com/q/9097298/153923
我想知道如何使用微软的技术来做到这一点......或者只是向我解释其他人在谈论什么以及如何使用它们。
基本上,如果有人在地址栏中输入“mydomain.com”,我希望在页面加载完成后将其解析为“www.mydomain.com”。
EDIT:这是一个托管网站,因此我无法配置 IIS 服务器。
- 非 www 到 www 重定向
- www.yourdomainname.com/default.aspx 至 www.yourdomainname.com
现在在 web.config 中添加 config 标签
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^yourdomainname.com$" />
</conditions>
<action type="Redirect" url="http://www.yourdomainname.com/{R:0}" redirectType="Permanent" />
</rule>
<rule name="Default Document" stopProcessing="true">
<match url="(.*?)/?default\.aspx$" />
<action type="Redirect" url="{R:1}/" />
</rule>
</rules>
</rewrite>
</system.webServer>
(或)选择这个:
<rewrite>
<globalRules>
<rule name="Redirects to www.domain.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^domain.*(com|net)$" />
<add input="{HTTP_HOST}" pattern="^(www.)?mydomain2.(com|net)$" />
<add input="{HTTP_HOST}" pattern="^www.domain.net$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:0}" />
</rule>
</globalRules>
</rewrite>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)