重写规则不适用于 IIS


rewrite rules don't work on IIS

我正在IIS上做php编程。我正在使用的 php 框架是 Yii。隐藏index.php并使用友好 URL 我在config.php文件上启用了urlManager。我的问题是,当我尝试导航到我的控制器服务器时,返回错误 404。我认为重写规则有问题,但我不熟悉IIS Web 服务器。有人可以帮助我吗?

我已经

解决了我的问题。 这是.htaccess中的原始规则:

RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php

这是web.config格式的翻译:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
    <rewrite>
        <rules>
        <rule name="Hide Yii Index" 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>
                <action type="Rewrite" url="index.php" appendQueryString="true" />
        </rule> 
        </rules>
    </rewrite>
</system.webServer> 
</configuration>