微软重写模块 - 强制WWW上的URL或网址中的www [英] Microsoft rewriting module - Force www on url Or remove www from url
问题描述
我有Windows Server 2008和IIS7.5一个共享的托管计划,并没有安装Microsoft重写模块并启用。
I have a shared hosting plan with Windows Server 2008 and IIS7.5, and there is Microsoft rewriting module installed and enabled.
<rewrite>
<rules>
<rule name="myRule" patternSyntax="Wildcard">
<!--Rewriting code-->
</rule>
</rules>
</rewrite>
那么,如何重定向mydomain.com/everywhere-in-site/my-page.html与微软重写模块www.mydomain.com/everywhere-in-site/my-page.html~~V?
So, how to redirect mydomain.com/everywhere-in-site/my-page.html to www.mydomain.com/everywhere-in-site/my-page.html with Microsoft rewriting module?
而如果我想重定向到www.mydomain.com/everywhere-in-site/my-page.html mydomain.com/everywhere-in-site/my-page.html~~V?
And what if I want to redirect www.mydomain.com/everywhere-in-site/my-page.html to mydomain.com/everywhere-in-site/my-page.html ?
推荐答案
要从域中删除www和重定向到一个裸域你可以迪像在以下code片断:
To remove the www from a domain and redirect to a "naked domain" you could di it like in the following code snippet:
<rewrite>
<rules>
<rule name="Remove WWW prefix" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.yourdomain\.com$" />
</conditions>
<action type="Redirect" url="http://yourdomain.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
和周围的其他方法(如果preFER即),以一个非www重定向一个以www
And the other way around (if you prefer that) to redirect a non-www to one with www:
<rewrite>
<rules>
<rule name="Add WWW prefix" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^yourdomain\.com$" />
</conditions>
<action type="Redirect" url="http://www.yourdomain.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
的 redirectType =永久
当然是可选的,但对于搜索引擎优化和大多数情况下我会推荐它。
The redirectType="Permanent"
is of course optional but for SEO and most scenarios I would recommend it.
请也看到这些做题/答案:
Please see also these SO questions/answers:
- IIS7 URL重写 - 新增] WWW&QUOT; preFIX
- Forwarding http://mydomain.com/ctrlr/act/val到http://WWW.mydomain.com/ctrlr/act/val
- Proper方法使用IIS URL地址从除去WWW重写
- IIS7 URL Rewrite - Add "www" prefix
- Forwarding http://mydomain.com/ctrlr/act/val to http://WWW.mydomain.com/ctrlr/act/val
- Proper method to remove www from address using IIS URL Rewrite
这篇关于微软重写模块 - 强制WWW上的URL或网址中的www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!