【发布时间】:2015-09-16 14:55:07
【问题描述】:
我在 Azure 中托管我的 AngularJS 站点,但是当我只想对 www.url 执行 URL 重写时遇到了问题。版本。我正在使用 HTML5 模式进行路由。
如果我有以下 web.config 并刷新页面,我会收到一条错误消息,指出“您要查找的资源已被删除、名称已更改或暂时不可用。”
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear/>
<rule name="WWW Rewrite" enabled="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\."/>
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
如果我将 web.config 保留如下,刷新没有问题,但我无法重定向到 www。我的网站版本:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
我怎样才能让这两个场景一起工作?
【问题讨论】: