Question : Apache mod-rewrite question dealing with folders

Hi,
Wonder if someone can help. I think this query is pretty basic, but I could be wrong. I have a .htaccess file as follows:

[START of HTACCESS]
RewriteEngine On

# Prevent looping for files with an extension
RewriteCond %{REQUEST_URI}!^/.+\.[a-z5]{2,4}$

# dept redirect
RewriteRule ^([a-zA-Z0-9]+)$ dept.php?dn=$1 [L]

# employee redirect
RewriteRule ^([a-zA-Z0-9]+)-([a-zA-Z0-9]+)$ emp.php?dn=$1&en=$2 [L]

[END of HTACCESS]

Now the above works fine. URLs such as:

http://www.mydomain.com/finance
http://www.mydomain.com/marketing

all redirect fine. As does
http://www.mydomain.com/marketing-fred

Lovely. However, a URL such as

http://www.mydomain.com/finance/ - redirects to the PHP file no problem, but the CSS file is not included. It appears that the extra "/" on the end has somehow mangled the path to the CSS .... the CSS is included using ''

I have tried:

 RewriteRule ^([a-zA-Z0-9]+)$ dept.php?dn=$1 [L]
but makes no difference.

Once I get this working, I'd like to move to separators using "/" as opposed to "-" as used currently.

Any suggestions anyone as to how to deal with this folder issue?

Thanks,
B

Answer : Apache mod-rewrite question dealing with folders

Since there is a slash on the end, the browser looks for the css at "/finance/css/main.css".  There two ways to solve this:
1. Force there to not be a trailing slash
2. prepend the path to the css with a php variable that contains the relative path to make it work (this is what I do on my sites)
for example:
global $relpath;
# determine the relative path
$depth=substr_count($_SERVER['REQUEST_URI'],"/")-1;
$relpath='';
if ($depth)
      for ($x=0;$x<$depth;$x++)
            $relpath = $relpath . "../";
?>

and wherever you reference a path that is relative to the root, you echo the $relpath.  for example:


Random Solutions  
 
programming4us programming4us