This query confronts an issue where URL rewriting successfully redirects browsers to the desired page; however, loading of CSS, JS, and images fails. To provide further explanation:
Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteRule ^detail/([0-9]+)/?$ detail.php?id=
The proposed solution of using absolute paths for the problematic resources addresses the root of the problem. By explicitly specifying the exact location of these files (e.g., /css/myfile.css instead of /css/), the browser can directly access them without needing to append the modified base URI.
An alternative approach to resolving the issue involves adjusting the URI base of the pages after URL rewriting. This is possible by inserting a
<head> <base href="/"/> ... </head>
By using this tag, the browser is instructed to treat all relative URIs on the page as if they were relative to the root directory (/). This ensures that CSS, JS, and images are loaded correctly despite the modified base URI caused by the rewriting rules.
The above is the detailed content of Why Aren't My CSS, JS, and Images Loading After URL Rewriting?. For more information, please follow other related articles on the PHP Chinese website!