Secure SRC url by HTACCESS

0

I'm using friendly URL via HTACCESS and because I'm using this the pages lose the styles and js. Because the path (URL) is done as ex / category / pizza then it looks for src="category / pizza / style.css". Would there be any way to fix the base URL through HTACCESS?

    
asked by anonymous 22.07.2014 / 05:53

3 answers

0

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

    
22.07.2014 / 13:13
0

In this case the ideal is to specify the path of the files for a) full URL or b) relative path (eg "/style.css" or "/css/style.css"). This problem is not related to htaccess

    
22.07.2014 / 06:24
0

An alternative is to set the <base> tag in the header of HTML pages.

link

Also set httaccess the rewrite rule exception for when to find a folder or file, such as the base where the rule will be applied.

RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
    
22.07.2014 / 12:22