I have implemented clean URLs using the following in my .htaccess
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
And in my index.php the $_SERVER['PATH_INFO'] is parsed to determine the requested page and any parameters.
This all works fine, however any requests for a url with more than one segment, i.e.
www.example.com/page/foo/bar
cause all linked assets (css, js, images) and hyperlinks on the page to break because they use relative paths. A absolute path with an implied domain (aka prepending all paths with “/”) is not viable because the site has to be accessible and working properly as a subdirectory of a parent website in addition to its own root URL. I can not hardcode the fully qualified absolute path for all links either, as I do not have control over some of the content that will be on the page. Using the <base> tag is also not an possibility.
Do I have any other options here?
Does every request to PHP fall on the same
index.phpfile? In that case, the file itself knows where it is, and can calculate what directory it’s in.This isn’t the neatest way to do it, but it might give you some ideas to work from.
And then prepend all links with
BD.