编程技术 · 2024年4月21日

iisexpress下伪静态配置不生效的可能原因

首先,通过转换工具,把伪静态配置文件从apache转换成IIS的格式
apache
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]

IIS
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="rewriteTools4" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^(.*)" ignoreCase="false" />
                     <conditions> 
                         <add input="{REQUEST_FILENAME}" matchType="IsFile"  ignoreCase="false" negate="true" /> 
                         <add input="{REQUEST_FILENAME}" matchType="IsDirectory"  ignoreCase="false" negate="true" />
                    </conditions>
                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="index.php?/{R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

</configuration>
然后,放到web根目录的web.config文件中,调试使用,但并没有生效.刚开始一直怀疑iisexpress的rewrite组件配置有问题,搜寻了不少似是而非的答案,根本解决不了问题.
后来,重新把焦点集中在配置文件上,经过无数次的测试,终于找到原因,在iis里这个match表达式,不能带前后标记^$,然而,这么一个简单的原因,在网上居然找不到案例或相关说明.导致我走了不少冤枉路.特此存档记录给有需要的人.
最终生效配置
<rule name="myRewrite" patternSyntax="ECMAScript" stopProcessing="false">
  <match url="/(.*)" ignoreCase="true" />
  <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
  </conditions>
  <action type="Rewrite" url="/index.php/{R:1}"/>
</rule>
另外,也要说一下,这个网上找的转换工具,虽然可以大致完成转换,但一些细节上的问题并没有处理好,对于像我这样的新手,会有很多坑.

最新电影,电视剧,尽在午夜剧场

电影电视剧午夜不寂寞