Routing system ignoring subfolders

0

I am using the routing system AltoRouter , and its use is quite simple, use this way:

**** THIS IS INDEX.PHP *****

/*Incluo o arquivo do AltoRouter*/
include ('application/router.php');

$router = new AltoRouter();
$router -> setBasePath('/mvc/'); ** aqui é o diretório base **

$router -> map('GET', 'noticia', 'noticia#index', 'noticia');

$match = $router -> match();

**Aqui a estrutura da chamada controlller#action no padrão MVC**

if ($match === false) {

header('Location: /mvc/error');

} else {

list($controller, $action) = explode('#', $match['target']);

if (is_callable(array($controller, $action))) {
    $obj = new $controller;
    call_user_func_array(array($obj, $action), $match['params']);
} else {

    exit('O Controller não pôde ser chamado');

}
}

the .htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

The problem is that when calling a view through the VIEW class (where the frontEnd files are called) ... the frontEnd part directory (css, js and images) is not recognized, the system thinks it is a controller, example:

<link rel="stylesheet" href="public/main.css">

The page can not find the file / directory (public / main.css) and is redirected to the error page as defined in the above code.

I do not understand much about regular expressions, but I think that's it, how can I solve it?

    
asked by anonymous 05.10.2015 / 03:29

1 answer

1

In the .htacess file, add the following

RewriteCond %{REQUEST_FILENAME} !-d

This code says that you should ignore the rewrite rule if it finds a valid physical directory.

Another point is loading css, js, and others into HTML, including for images.

To ensure path integrity, set the base of URLs with the tag <base>

Example: <base href="http://endereço.base.do.site/" target="_blank">

link

If you do not want to use the <base> tag, specify absolute paths or relative more concise paths.

    
05.10.2015 / 11:07