【问题标题】:IIS URL forwarding reports HTTP error 404 with KLEIN.phpIIS URL 转发使用 KLEIN.php 报告 HTTP 错误 404
【发布时间】:2020-08-06 13:55:55
【问题描述】:

我是 IIS 的初学者,到目前为止只使用过 Apache(使用 .htaccess)。 我的问题是,我只收到 404 错误消息,提示找不到页面。

只有当所有请求都由索引文件处理时,KLEIN.php 框架才能工作。 关于这个项目的所有文件都设置在根目录中: File structure on the server / Root

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

编辑:网络配置文件:

<?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" => "/"
);

【问题讨论】:

  • 您最好共享来自 applicationHost.config 或 web.config 的 XML 片段,其中包含您的重写规则。没有人可以轻松阅读屏幕截图,尤其是非英语的屏幕截图。
  • 我的错,刚刚添加了 web.config 文件。

标签: php iis url-rewriting routes url-routing


【解决方案1】:

尝试使用以下规则:

<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>

【讨论】:

猜你喜欢
  • 2015-10-18
  • 1970-01-01
  • 2012-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-02
  • 2013-02-08
相关资源
最近更新 更多