I have modified a website with a redirection to a single page:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
It works as it suppose to be. Everything is redirected to index.php. Here is a working example that display index.php with all images and css:
http://.....com/section1
The problem occur when I try :
http://....com/section1/subsection
The page is redirected to index.php, BUT no images, no css, no javascript. Inside the PHP script everything is like this directly linked to the images or css or javascript like:
<img src="images/images1.png> ... <img src="images2.png">
Why does url with many slash like .com../123/123/whatever does not work with images, css or javascript when .com/no_slash_url works?
You’re rewriting without redirection, so the client thinks it’s at the original unrewritten URL and all relative paths will be resolved relative to that URL. You should be able to work around this using the
<base>element:Let me try and clarify this with an example. If I have a page at
http://mysite.com/index.phpand all its images are athttp://mysite.com/images/, my images might be referenced with a relative url likeimages/myImg.png. The client translates this url using the current path in the address bar. Now if I rewrite my URLs so that they look likehttp://mysite.com/mycategory/myarticle, any relative images would resolve tohttp://mysite.com/mycategory/myimages/, which is incorrect. By adding the base tag:Each browser will now resolve the images relative to that path instead, correctly looking for
http://mysite.com/images/.