CSS, JS and images do not display with pretty url

When you use relative url’s, the browser will dynamically create a complete url by using the url of the resource it loaded. In other words: It uses the url as it is displayed in the address bar. In your case (www.domain.com/subfolder/index.php/key) it tries to load any relative url relative to www.domain.com/subfolder/index.php/. Your resources are however not located there.

You have two options to resolve this problem:

  • Convert your relative url’s into absolute url’s, at least absolute to the domain root. Something like <img src="https://stackoverflow.com/questions/27744603/img/unicorn.png"> should be turned into <img src="https://stackoverflow.com/path/to/img/unicorn.png">.

  • Add a base to your head element. This base will be used instead of the url of the resource to calculate the complete url. You should add <base href="https://stackoverflow.com/"> to your <head> element. / will then be used as the base of any relative url.

Leave a Comment