【发布时间】: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