How to resolve problems in HTML file calling?

Asked

Viewed 384 times

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 the files on the homework... when I use the path

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

It comes back out from the root of the project
am trying to use URL’s friendlies the . 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>

2 answers

2

One of the steps is to add these RewriteCond to do the 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 the CSS is general, use root-related paths:

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

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

See a little more about rewrite in this matter.

1


I solved this problem by creating a variable that stores the Project Directory, I do this by comparing the server path with the url and saving the similar folders, after that I just put the variable as prefix of all the site Urls.

$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);
}

Browser other questions tagged

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