加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

iis-7 – 为AngularJS配置IIS URL重写模块HTML5Mode仍无效

发布时间:2020-12-17 17:17:37 所属栏目:安全 来源:网络整理
导读:我搜索了一下有关配置IIS URL重写模块以使用AngularJS HTML5Mode的一些信息,甚至尝试了我在另一个问题上找到的信息: How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode? 我已经对上面链接中的问题中显示的IIS进行了更改,并
我搜索了一下有关配置IIS URL重写模块以使用AngularJS HTML5Mode的一些信息,甚至尝试了我在另一个问题上找到的信息:

How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode?

我已经对上面链接中的问题中显示的IIS进行了更改,并设置了基本URL,并且当我访问根站点时该站点正常工作(即http:// localhost / appname /).我的所有观点和路由都很好.

然而;当我尝试在新的标签页或浏览器窗口中访问特定的URL(即http:// localhost / appname / about)时,我得到一个404.还有什么我错过了吗???

我正在运行安装了URL重写模块的Windows 7,IIS 7.

**我不得不将协议分开,以允许接受示例URL.

解决方法

安装此扩展程序: https://www.iis.net/downloads/microsoft/url-rewrite

并将其添加到system.webServer下的web.config中

<rewrite>
  <rules>
    <clear />        
    <rule name="Html5Mode" enabled="true" stopProcessing="true">
      <match url="^(.+)$" negate="true" />
      <conditions>
        <add input="{REQUEST_URL}" pattern="^(.+)$" negate="true" />
      </conditions>
      <action type="Rewrite" url="/index.html" logRewrittenUrl="true"/>
    </rule>
    <rule name="AngularJS" enabled="true" 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="/index.html" />
    </rule>        
  </rules>
</rewrite>

这是完整的web.config,包括提供静态文件.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
          <rules>
            <clear />        
            <rule name="Html5Mode" enabled="true" stopProcessing="true">
              <match url="^(.+)$" negate="true" />
              <conditions>
                <add input="{REQUEST_URL}" pattern="^(.+)$" negate="true" />
              </conditions>
              <action type="Rewrite" url="/index.html" logRewrittenUrl="true"/>
            </rule>
            <rule name="AngularJS" enabled="true" 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="/index.html" />
            </rule>        
          </rules>
        </rewrite>
        <handlers>
           <clear />
            <add 
                name="StaticFile" 
                path="*" verb="*" 
                modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" 
                resourceType="Either" 
                requireAccess="Read" />
        </handlers>
        <staticContent>
            <mimeMap fileExtension=".*" mimeType="application/octet-stream" />
        </staticContent>
    </system.webServer>
</configuration>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读