简体   繁体   中英

web.config not working in IIS8.0

I am migrating a little PHP-Application to an Microsoft Azure WebApp.

I know that there are a lot similiar questions on stackoverflow but i can't figure it out on my own.

Previous i had this .htaccess file in one subdirectorie:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]
</IfModule>

I now have this web.config file, i generated it with an online tool and modified it a little bit.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="rule 1J" stopProcessing="true">
                <match url="(.*)"  ignoreCase="true" />
                <action type="Rewrite" url="/api.php?rquest={R:1}"  appendQueryString="true" />
            </rule>
            <rule name="rule 2J" stopProcessing="true">
                <match url="(.*)"  ignoreCase="true" />
                <action type="Rewrite" url="/api.php"  appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

Now i dont get an 404 error when trying to access the page. Seems like the web.config is not working at all.

Could please someone tell me whats wrong with my file?

There is a little mistake of regular expression.

This is my test project directory:

在此处输入图片说明

And here is my test web.config :

<?xml version="1.0"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="rule 1J" stopProcessing="true">
                <match url="^(.*)$"  ignoreCase="true" />
                <action type="Rewrite" url="/api.php?request={R:1}"  appendQueryString="true" />
            </rule>
            <rule name="rule 2J" stopProcessing="true">
                <match url="^(.*)$"  ignoreCase="true" />
                <action type="Rewrite" url="/api.php"  appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
</configuration>

The result is that when visiting <web_app_name>.azurewebsites.net , it matches the 2nd rule and rewrite to <web_app_name>.azurewebsites.net/api.php .

And when visiting <web_app_name>.azurewebsites.net/example , it matches the 1st rule and rewrite to <web_app_name>.azurewebsites.net/app.php?request=example

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