簡體   English   中英

為AngularJS HTML5Mode配置IIS URL重寫模塊仍然不起作用

[英]Configure IIS URL Rewrite module for AngularJS HTML5Mode Still Not Working

我搜索了一下有關配置IIS URL重寫模塊以使用AngularJS HTML5Mode的一些信息,甚至嘗試了我在另一個問題上找到的信息:

如何在HTML5模式下為URL重寫AngularJS應用程序配置IIS?

我已經對上面的鏈接中的問題中顯示的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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM