[英]Redirect to www in IIS7 - classic pipeline mode
I want to implement redirects on an IIS7 webserver. 我想在IIS7 Web服务器上实现重定向。 Basically, if the subdomain is not included in the URL, I will redirect to the www subdomain.
基本上,如果URL中未包含子域,我将重定向到www子域。
http://mysite.com/file.aspx redirects to http://www.mysite.com/file.aspx http://mysite.com/file.aspx重定向到http://www.mysite.com/file.aspx
http://mysite.com/image.jpg redirects to http://www.mysite.com/image.jpg http://mysite.com/image.jpg重定向到http://www.mysite.com/image.jpg
http://mysite.com/text.html redirects to http://www.mysite.com/text.html http://mysite.com/text.html重定向到http://www.mysite.com/text.html
How to do this? 这个怎么做?
I do not want to write any HTTP Module -- it must be done thru IIS config only. 我不想编写任何HTTP模块-必须仅通过IIS配置来完成。
Also, I am required to use Classic Pipeline mode and cannot install any ISAPI plugins. 另外,我必须使用经典管道模式,并且无法安装任何ISAPI插件。
Is it possible? 可能吗?
You can throw this into your web.config file: 您可以将其放入web.config文件中:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^http://mysite.com$" />
</conditions>
<action type="Redirect" url="http://www.mysite.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
In IIS7 it can be done through the url rewrite section. 在IIS7中,可以通过url重写部分来完成。
This solution worked for me: 此解决方案为我工作:
1) Install URL Rewrite component: 1)安装URL重写组件:
http://www.iis.net/download/urlrewrite http://www.iis.net/download/urlrewrite
2) Add to web.config: 2)添加到web.config:
<system.webServer>
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mysite\.com$" />
</conditions>
<action type="Redirect" url="http://www.mysite.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.