Problem with includes using friendly urls

Asked

Viewed 109 times

0

I’m having a problem that is already driving me crazy, I’m using friendly urls in a system I’m making and the css files,js etc are not loading, I’ve seen several cases here that this happens because of not putting the path in the right way, but this I’ve already fixed and every page I’m using includes a file called config.php that has the base directory and the site url 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";

File . htaccess is 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 directed is 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 index_friend.php page and accessing directly for example http://localhost/iesav2/panel/login files load normally.

1 answer

0

No need to put url on link to include.

Just leave on the model below:

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

Then you look in the browser source code to see if you’re actually redirecting to the css file.

Browser other questions tagged

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