我刚刚创建了一个asp.net应用程序,可以查看不同的页面,比如课程页面。
我在IIS上运行一切: localhost:50717。
我有一个带有ng- routes.html标记的视图页面。最初,如果我想转到课程视图,我会输入: localhost:50717/routes.html#/courses。但是,我想做一些URL重写,这样我就可以这样做了: localhost:50717/courses
因此,在我的JS文件中,我输入了:
$locationProvider.html5Mode(true);在我的html页面的头部,我输入了:
<base href="/" />在我的web.config文件中,我在system.webServer XML标记中添加了以下代码:
<rewrite>
<rules>
<rule name="RewriteRules" stopProcessing="true">
<match url=".*"/>
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>当我转到: localhost:50717/routes.html并点击我的链接:课程
它将我带到localhost:50717/courses。当我删除该代码以启用url写入时,这也可以很好地工作。
只有当我尝试重新加载页面时,才会收到404错误,或者当我尝试转到localhost:50717时,它才会认为我要转到基目录,而不是routes.html页面。
我甚至在我的IIS上安装了URL重写:http://www.iis.net/downloads/microsoft/url-rewrite
我转到“下载URL重写模块2.0”,点击x64下载链接,它正确下载了,并且能够看到我的默认站点的URL重写。我还能在这里做些什么?
发布于 2016-09-03 05:49:42
如果"/routes.html“代表网站的根目录,则必须确保为应用程序的每个适当请求返回该文件的内容。
也就是说,当你调用"/Courses“时,你会得到一个404,因为没有对应的内容/路由/资源。您希望返回的是"/routes.html“的内容,然后让AngularJS路由再次接管客户端。
我建议重新阅读课程;使用“/#/AngularJS HTML5-mode”和"/Courses“之间的区别比乍一看更重要,reg。你应该如何设置你的路线。
https://stackoverflow.com/questions/39300864
复制相似问题