My current HTACCESS looks like this.
# Run everything else but real files through index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule ^(.*)$ index.php?p=$1 [NC,L,QSA]
Great piece of code where when I type in what would be a subfolder directory, it redirects as a parameter to index.php. Works great for something http://localhost/blah
(which redirects as http://localhost/index.php?p=blah
), but not so great for http://localhost/blah/boink
.
The problem with the latter is that the redirection does work and does redirect to index.php, but for some reason, the page believes that it is at the subfolder level, blah
. So all my hardcoded ../
for my js
, css
, include
and require_once
paths are now technically "wrong". Anyway of fixing this?
In PHP, when I try to do this:
$file_url = explode("/", $_SERVER['PHP_SELF']);
// subtract 1 for left / and 1 for current file
$dir_loop = count($file_url) - 2;
$up_dirs = "";
// loop until to root directory
for ($i=0; $i<$dir_loop; $i++) {
$up_dirs .= "../";
}
...this doesn't seem to work either, because the index.php is at the root folder level. I suspect this may be a HTACCESS issue? Thoughts?