在ionic这个框架下(Angular JS),对URL进行重写,过滤掉URL中的#号
此时URL的改变已经完全不受后台代码控制了,因此我们要在前端的ionic这个框架和IIS中进行修改调控。
其实IIS只是host了整个站点,具体的URL跳转都是由前端来控制的。
1):那么前端要加上一行代码:
$locationProvider.html5Mode(true);
2):IIS对应的web.config要做如下处理,是每次经过IIS的请求都跳回主页,那么后续的URL管理都由前台框架来管理了:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <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>
3):要保证上述config能够生效,需要安装IIS URL Rewrite的插件,具体下载地址如下所示:
http://www.iis.net/downloads/microsoft/url-rewrite
更多详细的信息请看如下链接:
https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode