L
L
Let_peace2020-08-30 23:40:48
PHP
Let_peace, 2020-08-30 23:40:48

How to fix problem with php scripts (working with .htaccess)?

.htaccess (this is just part of it): RewriteRule ^(.*)$ /index.php?key=$1 [L]
index.php:

<?php
$key = $_GET['key'];
    switch ($key) {
        case 'main':
            require_once './main.php';
            break;
        // ...
        default:
            require_once './error404.php';
    }
?>


The situation is this: if you access a non-existent file without going through any directories (ie, if you write http://domain/address_of_non-existent_file in the address bar ), then require_once './error404.php'; , but if you use directories (i.e. http://domain/existing_directory/address_not_existing... ), then an error will come out from the browser itself with a notification that such a page does not exist, i.e. require_once './error404.php'; does not work.

Tell me how to fix this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
felony13twelve, 2020-08-31
@felony13twelve

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

F
FanatPHP, 2020-08-31
@FanatPHP

you have another xtaxess in the existing directory, which cuts down the rules of the first

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question