正在将.htaccess转换为Azure的web.config


Converting .htaccess to web.config for Azure?

我这里有一个.htaccess文件,需要将其转换为web.config以用于Azure。这是htaccess文件:

Options +FollowSymlinks
Options -Multiviews
ErrorDocument 404 /error-404
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*'.php$ %{REQUEST_FILENAME}.php [NC,L]

我已经将其转换为web.config文件,但它不起作用。它只是抛出一个未找到的404错误。这是web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="rule 1C" stopProcessing="true">
                    <match url="!.*'.php$"  ignoreCase="true" />
                    <action type="Rewrite" url="/%{REQUEST_FILENAME}.php". />
                </rule>
            </rules>
        </rewrite>
        <defaultDocument>
            <files>
                <add value="test.php" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

除了重写之外,这个文件的所有内容都有效。只需要帮助就可以在Azure中显示没有.php文件扩展名的页面。

对于ErrorDocument 404 /error-404,请参见以下内容。

<system.webServer>
    <httpErrors>
        <remove statusCode="404" />
        <error statusCode="404" path="/error-404"  responseMode="ExecuteURL"/>
    </httpErrors>
</system.webServer>

有关重写url,请参阅下面的内容。

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="rule 1C" stopProcessing="true">
                    <match url="!.*'.php$" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        </conditions>
                    <action type="Rewrite" url="{R:1}.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>