.htaccess内容转换为Web.config内容

时间:2013-12-05 04:53:46

标签: php xml .htaccess

我在Apache的.htaccess中有这个url重写规则:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?route=$1 [L,QSA]

我知道希望将其转换为II7中的Web.config内容

<system.webServer>
    <rewrite>
        <rules>
            <rule name="DynamicRewrite" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{REQUEST_FILENAME}\.html" matchType="IsFile" />
                </conditions>
                <action type="Rewrite" url="/index.php?route={R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

它似乎是正确的吗?感谢

1 个答案:

答案 0 :(得分:1)

不是100%肯定,但你添加的条件是错误的。您拥有的条件是请求+“。html”是一个文件。你想要的是:

<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />

这等同于

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

部分apache重写规则。

所以:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="DynamicRewrite" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <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?route={R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>