How to solve problems in calling files in HTML?

1

I have a folder structure where I have the following architecture

page
    php
        arquivos.php
    tpl
        arquivos.tpl(html)
    style
        arquivos.css

But I have a problem calling files in tpl's ... when I use the path

<link type="text/css" rel="stylesheet" href="../style/style.css" />

It returns out of the root of the project
I'm trying to use friendly URL's .htaccess is like this

<IfModule mod_rewrite.c>
    RewriteEngine On
    Options -Indexes
    ErrorDocument 404 /Errors/404.html
    ErrorDocument 403 /Errors/403.html
    RewriteRule ^/?$ page/php/Home.php [NC,L]
    RewriteRule ^contato/?$ page/php/Contato.php [NC,L]
</IfModule>
    
asked by anonymous 25.04.2014 / 18:13

2 answers

1

I solved this problem by creating a variable that holds the project directory, I do this by comparing the server path with the url and saving the similar folders, after which I just put the variable as a prefix of all URLs in the site.

$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]/";
    $smarty->assign('Directory',$Directory);
}else{
    $Directory = "/";
    $smarty->assign('Directory',$Directory);
}
    
25.04.2014 / 19:38
2

One of the steps is to add these RewriteCond to make rewrite only when there is no file or folder with the requested name:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/?$ page/php/Home.php [NC,L]
RewriteRule ^contato/?$ page/php/contato.php [NC,L]

Additionally, in cases where CSS is general, use root-relative paths:

<link type="text/css" rel="stylesheet" href="/style/style.css" />

For CSS relative to the current document, just looking at the same specific case. Remember that what counts is the final path from where the page is being served, not where the script / template actually lies. Who will solve this path is the browser, not Apache, so take into account the path that appears when browsing the pages.

See a little more about rewrite in this question .

    
25.04.2014 / 18:56