在ionic这个框架下(Angular JS),对URL进行重写,过滤掉URL中的#号

此时URL的改变已经彻底不受后台代码控制了,所以咱们要在前端的ionic这个框架和IIS中进行修改调控。html

其实IIS只是host了整个站点,具体的URL跳转都是由前端来控制的。前端

1):那么前端要加上一行代码:html5

$locationProvider.html5Mode(true);

 

2):IIS对应的web.config要作以下处理,是每次通过IIS的请求都跳回主页,那么后续的URL管理都由前台框架来管理了:git

<?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的插件,具体下载地址以下所示:github

http://www.iis.net/downloads/microsoft/url-rewrite web

 

更多详细的信息请看以下连接:框架

https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5modeionic

相关文章
相关标签/搜索