URL rewriting : css, js, and images not loading

.htaccess, apache, mod-rewrite, php, url-rewriting

Solution

Don't be lazy and change your relative URIs in your resources to root directory absolute pathing like `/css/style.css`. This is the best.

You can get clever and use regex and replace all the files you need which would be like a few one liners and you're done. How many places could there be to change? And you should be using a template.

This should work but I wouldn't go this way.

`RewriteRule ^detail/(css|js|img)/(.*)?$ /$1/$2 [L,QSA,R=301]`

Problem

I've following rule for `.htaccess` ``` Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteRule ^detail/([0-9]+)/?$ detail.php?id=$1 ``` It redirects `http://localhost/detail/123` URL to `http://localhost/detail.php?id=123`. The page redirects successfully, but the problem is `CSS, JS, and images` are not loading, CSS, js files are located under `http://localhost/css/` and `http://localhost/js/` One solution is to use absolute path (ex /CSS, or /js rather than just CSS/, /js but this does not seem a reliable solution since we've to change it on all files, Any other solution based on `.htaccess` rules, which is independent of editing all PHP files and let us use "relative paths"?

Original source