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

本文介绍如何在Ionic前端框架和IIS服务器中配置URL,包括启用$locationProvider.html5Mode()以支持HTML5模式,并调整IIS web.config文件以确保所有请求返回主页,从而实现前端框架对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

 

转载于:https://www.cnblogs.com/mingmingruyuedlut/p/4236049.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值