【问题标题】:Web.Config IIS Rewrite RulesWeb.Config IIS 重写规则
【发布时间】:2016-02-17 00:27:13
【问题描述】:

我有一个将所有请求重定向到 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。

【问题讨论】:

    标签: asp.net iis web-config


    【解决方案1】:

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

    这也可以在 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>
    

    【讨论】:

      猜你喜欢
      • 2013-08-19
      • 2017-02-15
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      • 2015-07-10
      • 2013-02-01
      相关资源
      最近更新 更多