Jump to content

Getting folder information after rewrite rule applied


Fleur

Recommended Posts

I'm trying to link a stylesheet in a header that is included in each page. Some of the pages are in folders within folders etc so I want to make the link in the header globally link back to the right directory.

 

I was using '/' at the beginning which works fine until I open a file that has a rewrite rule applied. When I view page source it doesn't show the forward slash at the beginning.

 

I also tried code that I found on php.net which gets the current file directory relative to the root and works out how many '../' to add:

 

session_start();		    
$header_to_root_distance = 1;
$path = $_SERVER['QUERY_STRING'];
$header_dir = dirname($path);
$root_distance = substr_count($header_dir, DIRECTORY_SEPARATOR) - $header_to_root_distance;
$includer_distance = substr_count(dirname($_SERVER['SCRIPT_FILENAME']), "/");
$relative_path = str_repeat('../', $includer_distance - $root_distance);
$_SESSION['relative_path'] = $relative_path;

 

Again this works, but not on files that have a rewrite rule applied. In view source it shows the stylesheet link has no '../' at the beginning so I assume that once the rewrite rule is applied it loses all folder path information.

 

Please let me know what I can do to dynamically link the stylesheet for these pages.

 

Thanks in advance!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.