IIS URL转发使用KLEIN.php报告HTTP错误404

问题描述 投票:0回答:1

我是IIS的初学者,到目前为止仅与Apache(带有.htaccess)一起使用。我的问题是,iam只会显示404错误,并显示找不到任何页面的消息。

KLEIN.php框架仅在所有请求均由索引文件处理的情况下才有效。有关该项目的所有文件都在根目录中设置:File structure on the server / Root

我不认为这是框架,而是服务器配置,但是我不能排除它,所以我添加了代码示例

编辑:Web配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Importierte Regel 1" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="./index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

IIS配置:IIS URL REWRITE

从索引文件中提取:

 <?php
    //Require Settings & Database
    require_once 'settings.php';
    require_once 'db.php';

    //Load classes
    require_once 'inc/User.php';

    #######################
    # CREATE KLEIN OBJECT #
    #######################

    require_once __DIR__.'/vendor/autoload.php';
    $klein = new \Klein\Klein();


    #############################
    # DEFINE APP PATH FOR KLEIN #
    #############################

    define('APP_PATH', '/');
    $base  = dirname($_SERVER['PHP_SELF']);
    if(ltrim($base, '/')) $_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], strlen($base));


    ###########################
    # LOAD THE DEFAULT LAYOUT #
    ###########################

    $klein -> respond(function($request, $response, $service) {
        $service -> layout('layouts/default.php');
    });

    #########
    # PAGES #
    #########

    $klein -> respond('/', function ($request, $response, $service){
        $service -> pageTitle = '/ Home';
        $service -> render('views/welcome.php');
    });

    $klein->dispatch();

从设置文件中提取:

<?php
$settings = (object)array(
    "root_path" => "/"
);
php iis url-rewriting routes url-routing
1个回答
0
投票

尝试使用以下规则:

<rule name="Rerwite index.php" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" ignoreCase="true" />
    <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    </conditions>
    <action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
© www.soinside.com 2019 - 2024. All rights reserved.