如何配置IIS的URL重写在HTML5模式下AngularJS应用程序? [英] How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode?
问题描述
我有 AngularJS种子项目,然后我添加
$locationProvider.html5Mode(true).hashPrefix('!');
到app.js文件。我想IIS 7配置路由所有请求
to the app.js file. I want to configure IIS 7 to route all requests to
http://localhost/app/index.html
所以,这对我的作品。我该怎么做呢?
so that this works for me. How do I do this?
更新:
我刚刚发现,下载并安装了 IIS URL重写模块,希望这将使它很容易和明显,实现我的目标。
I've just discovered, downloaded and installed the IIS URL Rewrite module, hoping this will make it easy and obvious to achieve my goal.
更新2
我想这概括了我想要实现(从 AngularJS开发者文档一取>)
I guess this sums up what I'm trying to achieve (taken from the AngularJS Developer documentation):
使用该模式需要URL重写,服务器端,
基本上你不得不重写所有的链接入口点的
应用程序(例如,index.html)
Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html)
更新3:
我仍然在做这个,我意识到我需要不定向(有重写规则)某些URL,如
I'm still working on this and I realise I need to NOT redirect (have rules that rewrite) certain URLs such as
http://localhost/app/lib/angular/angular.js
http://localhost/app/partials/partial1.html
所以任何在CSS,JS,lib或谐音的目录不改向。其他的一切都需要被重定向到应用程序/ index.html的
so anything that is in the css, js, lib or partials directories isn't redirected. Everything else will need to be redirected to app/index.html
任何人知道如何无需添加一条规则为每一个文件,轻松实现这一目标?
Anyone know how to achieve this easily without having to add a rule for every single file?
更新4:
我在IIS URL定义2入站规则重写模块。第一条规则是:
I have 2 inbound rules defined in the IIS URL Rewrite module. The first rule is:
第二条规则是:
现在,当我浏览到本地主机/应用程序/加载的页面,但是支持文件(在CSS中的人,JS,lib和谐音目录)也被改写成应用程序/ index.html页面视图1 - 这样一切都回来的index.html页面,无论使用什么URL。我想这意味着我的第一个规则,即从第二条规则被处理应该是prevent这些URL,不工作..任何想法? ...任何人? ...我觉得很孤独......: - (
Now when I navigate to localhost/app/view1 it loads the page, however the supporting files (the ones in the css, js, lib and partials directories) are also being rewritten to the app/index.html page - so everything is coming back as the index.html page no matter what URL is used. I guess this means my first rule, that is supposed to prevent these URLs from being processed by the second rule, isn't working.. any ideas? ...anyone? ...I feel so alone... :-(
推荐答案
在这个问题做的工作给出的IIS入站规则。我必须清除浏览器缓存,并添加以下行的顶部我的< HEAD>
index.html页面的部分:
The IIS inbound rules as shown in the question DO work. I had to clear the browser cache and add the following line in the top of my <head>
section of the index.html page:
<base href="/myApplication/app/" />
这是因为我在多个应用程序本地主机等其他谐音请求都被带到本地主机/应用/视图1
而不是本地主机/所有MyApplication /应用/视图1
This is because I have more than one application in localhost and so requests to other partials were being taken to localhost/app/view1
instead of localhost/myApplication/app/view1
希望这可以帮助别人!
这篇关于如何配置IIS的URL重写在HTML5模式下AngularJS应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!