Here comes a question because my current solution is not really satisfying me for the following problem:
I have an own PHP Framework with MVC pattern in development. And my Router works perfect and all but I have one question I could not find a solution for.
Well I route every incoming request to index.php file which is located in the base-path of my framework. Ofcourse it is no problem to work with relative paths when including css such as:
<link rel="stylesheet" type="text/css" href="style/include/css/style.css" />
This works perfect in the browser. Ofcourse it does not matter what I enter in the URL because every request gets redirected as stated above to the index to make a reasonable routing possible.
However when my url contains multiple slashes which look like subfolders, for example: "/manual/details/1_2" then I get a normal routing process but the browser cannot find the css file unless I add "../" for each "/" in my url to map backwards to my base-path.
For example for the above URL this would work instead:
<link rel="stylesheet" type="text/css" href="../../style/include/css/style.css" />
My curent solution:
I wrote a PHP function in my Routing class that determines the required amount of "../" pattern and I always cast the function before implementing a resource to build the exact path at any time.
Example:
<link rel="stylesheet" type="text/css" href="<?=Router::getInstance()->getSubdirectoryPrefix()?>style/include/css/style.css" />
Needless to say that this is very unhandy and also sucks if you forget to place that function. If your route ever changes or you forget that you are in a subdirectory you will wonder why your resource could not be found.
I also know about putting an alias such as Alias /public style/ in my Virtual-Host configuration of Apache but I want to find another - project and PHP internal way without having an unhandy crap such as pasting the alias function all the time and without setting up a virtual-host option so the framework can stay lightweight and does not require any nasty external options like modifying Virtual-Host.
I'd love to hear your solutions, best would be .htacces - oh and by talking over it I leave my .htaccess code here aswell:
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]
Thanks in advance for your help~