File . htaccess and php route

Asked

Viewed 27 times

0

I’m having trouble creating a route on my localhost that will be later placed on the www server, it always redirects to the 404 even the existing folder, follow settings that esotu using

file . htaccess

 RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*) ?$1

<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>

index.php file at the root of the localhost/new_site folder

<?php
$SERVER             = ($_SERVER ?? null);
$REQUEST_URI        = filter_input(INPUT_SERVER, 'REQUEST_URI');
$INITE              = strpos($REQUEST_URI, '?');

$DIR_BASE           = 'new_site';
$FIRST_DIR          = 'home/';

if ($INITE) :
    $REQUEST_URI    = substr($REQUEST_URI, 0, $INITE);
endif;

$REQUEST_URI_PASTA  = substr($REQUEST_URI, 1);
$URL                = explode('/', $REQUEST_URI_PASTA);
$URL[0]             = ($URL[0] != '' ? $URL[0] : 'home');

if (file_exists($FIRST_DIR . $URL[0] . 'php')) :
    require($FIRST_DIR . $URL[0] . 'php');
    echo $URL[0];
elseif (is_dir($FIRST_DIR . $URL[0])) :
    if (isset($URL[1]) && file_exists($FIRST_DIR . $URL[0] . '/' . $URL[1]) . 'php') :
        require($FIRST_DIR . $URL[1] . 'php');
        echo $URL[0];
    endif;
else :
    require($FIRST_DIR . '404.php');
    echo $URL[0];
endif;

I’m using a folder structure like this:

-> localhost
        -> new_site
        -> inicio
            ->css
                ->style.css
            ->scripts
                ->scripts.js
            -> inicio.php
            -> prodtuo.php
            -> categorias.php
        -> admin
            ->css
                ->style.css
            ->scripts
                ->scripts.js
            -> inicio.php
            -> adm_produtos.php
            -> adm_categorias.php
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.