0
votes

I'm a beginner in IIS and have only worked with Apache (with .htaccess) so far. My problem is that iam only getting a 404 ERROR with the message that no page can be found.

the KLEIN.php framework only works if all requests are handled by the index file. All files about this project are set in the root directory: File structure on the server / Root

I don't think it's the framework but the server configuration, but i can't rule it out, so i add the code examples

EDIT: Web Config File:

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

The IIS Config: IIS URL REWRITE

Extract from the index file:

 <?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();

Extract from the settings file:

<?php
$settings = (object)array(
    "root_path" => "/"
);
1
You'd better share the XML fragment from applicationHost.config or web.config that contains your rewrite rules. No one can easily read a screen shot, especial in non-English.Lex Li
My bad, just added the web.config file.Mats

1 Answers

0
votes

try to use the below rule:

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