我想在 IIS7 网络服务器上实现重定向。基本上,如果 URL 中不包含子域,我将重定向到 www 子域。
http://mysite.com/file.aspx重定向到 http://www.mysite.com/file.aspx
http://mysite.com/image.jpg重定向到 http://www.mysite.com/image.jpg
http://mysite.com/text.html重定向到 http://www.mysite.com/text.html
如何做到这一点?
我不想编写任何 HTTP 模块——它只能通过 IIS 配置完成。
此外,我需要使用经典管道模式并且不能安装任何 ISAPI 插件。
这可能吗?
最佳答案
您可以将其放入您的 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>
在 IIS7 中,它可以通过 url 重写部分来完成。
关于iis-7 - 在 IIS7 中重定向到 www - 经典管道模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4445285/