Fleur Posted April 16, 2010 Share Posted April 16, 2010 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! Link to comment https://forums.phpfreaks.com/topic/198720-getting-folder-information-after-rewrite-rule-applied/ Share on other sites More sharing options...
Sergey Popov Posted April 16, 2010 Share Posted April 16, 2010 I would suggest to use / as you initially did and which worked for you... but also add to the page header: <base href="<?php echo $_SERVER["SERVER_NAME"] ?>/"> Link to comment https://forums.phpfreaks.com/topic/198720-getting-folder-information-after-rewrite-rule-applied/#findComment-1042897 Share on other sites More sharing options...
Fleur Posted April 16, 2010 Author Share Posted April 16, 2010 Thanks for your suggestion. I actually had a typo in the header link on that page - after days of frustration. sorry... Link to comment https://forums.phpfreaks.com/topic/198720-getting-folder-information-after-rewrite-rule-applied/#findComment-1042900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.