vue单页面 iis跨域重写规则与history模式的规则冲突

新手上路,请多包涵

我用的iis10服务器,需要实现跨域请求,同时呢,也要保证vue history模式刷新页面时候不会报404等问题,于是在web.config中添加两个相反的规则,代码如下。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>

<rewrite>
  <rules>
    
    <!-- 规则1 -->
    <rule name="jjss_data2">
      <match url="^api/(.*)" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^t\.jjss\.com$" />
      </conditions>
      <action type="Rewrite" url="http://b.jjss.com/{R:1}" />
    </rule>

    <!-- 规则2 -->
    <rule name="Handle History Mode and custom 404/500" 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>

当url中包含api时候,重写规则为1,重写域名请求服务器数据,当url中不包含api时候,重写规则为2,history模式下刷新页面没问题。这两个规则,分别存在时候,对应的情景都正常,但是把这两个规则像上面一起写的时候,规则1失效了,api接口请求报以下错误:

HTTP 错误 500.50 - URL Rewrite Module Error.
您查找的资源存在问题,因而无法显示。

详细错误信息:
模块 RewriteModule
通知 BeginRequest
处理程序 ExtensionlessUrlHandler-Integrated-4.0
错误代码 0x8007000d
请求的 URL http://t.jjss.com:80/api/data/article/list?page=1&cat=0
物理路径 E:webappwebdistapidataarticlelist
登录方法 尚未确定
登录用户 尚未确定

要怎么配置呢。

阅读 3.1k
1 个回答

我对问题的理解是:vue的history模式如何在iis中发布

iis下vue的history模式发布配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <customErrors mode="On" defaultRedirect="index.html">
            <error statusCode="404" redirect="index.html" />
        </customErrors>
    </system.web>
    <system.webServer>
        <httpErrors errorMode="Custom">
            <remove statusCode="404" />    
            <remove statusCode="500" />          
            <error statusCode="500" path="/index.html" responseMode="ExecuteURL" />
            <error statusCode="404" path="/index.html" responseMode="ExecuteURL" />
        </httpErrors>
      
    </system.webServer>
</configuration>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题