首页 > 解决方案 > 如何将 .htaccess 文件中的条件转换为 web.config

问题描述

我有这个 .htaccess 文件:

RewriteCond %{REQUEST_URI} !/admin/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^(.*)$ rewrite.php

如何在 web.config 文件中重写它?

标签: php.htaccessiisweb-config

解决方案


尝试这个

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="/admin/" ignoreCase="false" negate="true" />
                        <add input="{THE_REQUEST}" pattern="^[A-Z]{3,}\s([^.]+)\.php" />
                    </conditions>
                    <action type="Rewrite" url="rewrite.php" />
                </rule>
            </rules>
        </rewrite>

    </system.webServer>
</configuration>

推荐阅读