I’m working on a site which routes all requests through the index.php, but i have a problem with image, css and js includes.
My problem is:
The sites url can vary as example http://www.mysite.com, http://www.mysite.com/news/, http://www.mysite.com/news/something.
I generate all these pages dynamically through index.php.
My css files are linked as public/css/mycss.css.
if my url is http://www.mysite.com or http://www.mysite.com/news/ no problem, my files are loaded, but the url is http://www.mysite.com/news/something obviously my files are searched in the news/public/css directory and can’t be found.
Is there a good way to redirect all request for static files to the public directory.
Example:
/news/public/css/mycss.css
/news/public/images/myimage/myimage.jpg
/news/public/images/myimage/flags/myflag.jpg
to
public/css/mycss.css
public/images/myimage/myimage.jpg
public/images/myimage/flags/myflag.jpg
There could be many files and the directory structure inside public folder can vary.
You need to add this in the header of your pages:
So that all of your relative URLs get the currect URI base applied to it.