简体   繁体   English

为AngularJS HTML5Mode配置IIS URL重写模块仍然不起作用

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

I have searched at found some info on configuring IIS URL Rewrite module to work with AngularJS HTML5Mode and even tried the info I found on another question: 我搜索了一下有关配置IIS URL重写模块以使用AngularJS HTML5Mode的一些信息,甚至尝试了我在另一个问题上找到的信息:

How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode? 如何在HTML5模式下为URL重写AngularJS应用程序配置IIS?

I've made the changes to my IIS as displayed in the question found in the link above and set the base URL and the site works when I visit the root site (ie http: //localhost/appname/). 我已经对上面的链接中的问题中显示的IIS进行了更改,并设置了基本URL,并且当我访问根站点时网站正常工作(即http:// localhost / appname /)。 All of my views and the routing works fine. 我的所有观点和路由都很好。

However; 然而; when I try to visit a specific URL (ie http: //localhost/appname/about) in a new tab or browser window, I get a 404. Is there something else I'm missing??? 当我尝试在新的标签页或浏览器窗口中访问特定的URL(即http:// localhost / appname / about)时,我得到了404.还有什么我不知道的吗???

I'm running Windows 7, IIS 7 with the URL Rewrite Module installed. 我正在运行安装了URL重写模块的Windows 7,IIS 7。

** I had to space the protocol out to allow the example URL to be accepted. **我不得不将协议分开,以允许接受示例URL。

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

And add this to web.config under system.webServer 并将其添加到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>

Here is the full web.config including serving static files. 这是完整的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