Search code examples
phpcssmod-rewriteradix

Mod_rewrite inclusion problem with css


I new to mod_rewrite.

i have this page profiles.php?page=XXX

i tried to move it to more friendly url /cars/XXX/

RewriteEngine on
RewriteRule ^cars/([^/]+)/?$ profiles.php?page=$1 [L]

problem is when i include style

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

it doesnt work,

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

works fine, but wont work with profile.php?carname=XXX

why is that happening ? how can i fix it

Note:

I have a small script that determine the base address of website by counting number of /

global $base_addr;
$s=substr_count($_SERVER['SCRIPT_NAME'],"/",2)-1;
$base_addr=".";
if($s > 0)$base_addr.=str_repeat("/..",$s);
require_once($base_addr.'class/xxx.php');
echo "<link href='$Base_addr/css/style.css' rel='stylesheet' type='text/css' />";

In this code require_once will works perfectly, only html hrefs is my problem any fix for that


Solution

  • I think that this works better.

    <base href="/" />  
    

    Especially since you can define the base root of your site, then none of the assets like css or jquery in sub directories get lost.

    <base href="www.url.org/" /> 
    <base href="www.url.org/directory/" />