My recommendation is that you always specify the absolute path of the file, since PHP interprets based on the server path and the src
and href
in relation to the browser path... in such cases you would have to create a variable or a constant to resolve 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 variable above I compare the path of the server with the path of the browser, if the folder is the same in the 2, it saves in the variable... then we src
and href
I put the variable always in front of the absolute path. Ex:
<a href="{$Directory}images/press/large/image.jpg">
And here the folder imagens
is at the root of my project
Now something I consider very important, why not use the tag <base>
?
Simple, because it is not compatible with old browsers, IE9 or earlier will still not find your files, IE, you would have to stop giving support for 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 could find, at least it was the only one compatible with all needs and all browsers... I couldn’t find any way to do it directly by . htaccess
We await a feedback on the answers already given
– RodrigoBorth