简体   繁体   中英

Converting .htaccess to web.config for Azure?

I have here an .htaccess file that I need to convert to a web.config for use with Azure. Here is the htaccess file:

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

I have already converted this to a web.config file, but it does not work. It just throws a 404 error not found. Here is the 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>

Everything about this file works except the rewrite. Just need help getting the pages to show up without the .php file extension in Azure.

For ErrorDocument 404 /error-404 , please see below.

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

For rewriting url, please see below.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM