My recommendation is that you always specify the absolute path of the file, since PHP interprets based on the server path and src
and href
relative to the browser path ... in these cases you would have to create a variable or a constant to solve this difference
$UrlSite = explode(DIRECTORY_SEPARATOR,trim(parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH), '/\'));
$DirSite = explode(DIRECTORY_SEPARATOR,__DIR__);
if(in_array($UrlSite[0], $DirSite) AND $UrlSite[0] != ''){
$Directory = "/$UrlSite[0]/";
//é atribuido ao smarty {$Directory} no arquivo de configuração do smarty
}else{
$Directory = "/";
}
In the above variable I compare the server path with the browser path, if the folder was the same in the 2, it writes to the variable ... then the src
and href
put the variable always in front of the absolute path Ex:
Since here the folder imagens
is in the root of my project
Now something that I consider very important, why not use the <base>
tag?
Simple, because it does not have compatibility with old browsers, IE9 or earlier will still not find your files ie you would have to stop supporting these versions ...
My htaccess is as follows
<IfModule mod_rewrite.c>
RewriteEngine On
Options -Indexes
ErrorDocument 404 /Errors/404.html
ErrorDocument 403 /Errors/403.html
RewriteRule ^/?$ page/php/Home.php
</IfModule>
At first this was the best solution I found, at least it was the only one compatible with all the needs and with all browsers ... I did not find any way to do this directly through .htaccess