Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Web.Config IIS重写规则_Asp.net_Iis_Web Config - Fatal编程技术网

Asp.net Web.Config IIS重写规则

Asp.net Web.Config IIS重写规则,asp.net,iis,web-config,Asp.net,Iis,Web Config,我有一个将所有请求重定向到index.php的站点。但是,我需要对我的web.config稍作更改 这是重定向部分中当前的内容: <rewrite> <rules> <rule name="Process" stopProcessing="true"> <match url=".*" /> <conditions> <add i

我有一个将所有请求重定向到index.php的站点。但是,我需要对我的web.config稍作更改

这是重定向部分中当前的内容:

<rewrite>
    <rules>
        <rule name="Process" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php" />
        </rule>
    </rules>
</rewrite>

但是,我需要它,这样如果有人转到/news,它就会转到
news.php
,而不是
index.php


我会使用什么规则?我会把它放在哪里?我来自Apache背景,但我的客户端正在使用IIS。

您可以在现有的上插入另一条规则,只需进行一些更改即可重定向到您的位置

这也可以在IIS管理器中完成。这样做将允许您测试所使用的语法,以查看它是否适用于所需的URL

<rule name="Rewrite-News" patternSyntax="ExactMatch" stopProcessing="true">
    <match url="news" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="news.php" appendQueryString="false" />
</rule>

所以看起来有点像这样:

<rewrite>
    <rules>
        <rule name="Rewrite-News" stopProcessing="true">
            <match url="news" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="news.php" appendQueryString="false" />
        </rule>
        <rule name="Process" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php" />
        </rule>
    </rules>
</rewrite>