简体   繁体   English

web.config在IIS8.0中不起作用

[英]web.config not working in IIS8.0

I am migrating a little PHP-Application to an Microsoft Azure WebApp. 我正在将一些PHP应用程序迁移到Microsoft Azure WebApp。

I know that there are a lot similiar questions on stackoverflow but i can't figure it out on my own. 我知道在stackoverflow上有很多类似的问题,但是我不能自己解决。

Previous i had this .htaccess file in one subdirectorie: 以前我在一个子目录中拥有此.htaccess文件:

<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. 我现在有了这个web.config文件,我用一个在线工具生成了它,并对其做了一些修改。

<?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. 现在,当我尝试访问页面时,我没有收到404错误。 Seems like the web.config is not working at all. 似乎web.config根本不起作用。

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 : 这是我的测试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 . 结果是,访问<web_app_name>.azurewebsites.net ,它与第二条规则匹配,并重写为<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 当访问<web_app_name>.azurewebsites.net/example ,它匹配第一条规则并重写为<web_app_name>.azurewebsites.net/app.php?request=example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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