首页 > 解决方案 > 使用 url rewrite 模块创建规则将所有流量重写到 php

问题描述

我遇到的问题是我无法正确访问我的api的端点,总是返回404或403。api是在iis 8中用slim创建的,结构如下:

项目结构

我的 web.config 位于 /v1/Web.config 中(图中项目的末尾),其代码如下:

<?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="rule" patternSyntax="Wildcard">
                        <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.phk" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>

我需要当用户调用url“ http://myserverip/api/v1 ”时去公共文件夹中找到index.phk文件,不管用户调用端点还是root/v1,它都有总是去 index.phk。感谢您的关注,对不起我的英语。

标签: phpiisurl-rewritingweb-config

解决方案


很确定块logicalGrouping内属性的默认值是,因此默认情况下 IIS 会尝试匹配既是文件又是目录的请求。如果您插入应该匹配任一条件:<conditions/>MatchAlllogicalGrouping="MatchAny"

<conditions logicalGrouping="MatchAny">

另外,你的动作需要前导/,我不会提到你拼写index.php index.phk...

<action type="Rewrite" url="/index.php" />


推荐阅读