Problem with includes using friendly urls

0

I have a problem that is already making me crazy, I am using friendly urls in a system I am doing and the css files, js etc are not loading, I have already seen several cases here that this happens because of not putting the path but I've already arranged it and every page I'm using includes a file called config.php which has the base directory and the url of the site stored in variables:

<link rel="stylesheet" href="<?php echo $url_base; ?>/painel/css/font-awesome.min.css">

Config.php file:

<?php
$path_base = dirname(__FILE__);
$url_base = "http://localhost/iesav2";

.htaccess file looks like this:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule ^error404/?$ 404.php [NC,L]
RewriteRule ^adm_usuarios/?$ adm_usuarios.php [NC,L]
RewriteRule ^login/?$ login.php [NC,L]
RewriteRule ^adm_usuarios/([0-9]+)/([a-z0-9-]+)/?$ adm_usuarios.php?nivel=$1&pesquisa=$2 [NC]
RewriteRule ^adm_usuarios/([0-9]+)/?$ adm_usuarios.php?nivel=$1 [NC]
RewriteRule ^adm_usuarios/([a-z0-9-]+)/?$ adm_usuarios.php?pesquisa=$1 [NC]
RewriteRule ^(.*)$ index_friend.php

The index_friend.php file where the pages are targeted looks like this:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_erros', 1);
error_reporting(E_ALL);
require_once '../config.php';
//Pega toda url apos o dominio e transforma em array
$url = explode("/", $_SERVER['REQUEST_URI']);
//Pega diretório base e transforma em array
$path = explode("/", dirname(__FILE__));
//Compara a url com diretório base e remove o que não precisa
$url = array_diff($url, $path);
//Reseta indices do array
$url = array_values($url);
//Remove extensoes do nome do arquivo
$url[0] = str_replace(array('.php','.html'), '', $url[0]);
//Nome do arquivo requisitado
$file = $url[0].'.php';
//Se o arquivo existir então faz include para dentro
if(file_exists($file)){
    include ($path_base.'/painel/'.$file);
}else{ // Se não exibe error
    include ($path_base.'/painel/404.php');
}

Without using the page index_friend.php and directly accessing for example link the files load normally.

    
asked by anonymous 02.10.2017 / 01:00

1 answer

0

You do not need to put url in the link to include.

Just leave it in the template below:

  <link rel="stylesheet" href="/painel/css/font-awesome.min.css">

From there you look in the source code of the browser to see if it is actually redirecting to the css file.

    
02.10.2017 / 05:25