apache mod_rewrite problem: all css/js/images 404 |
Rather than using an .htaccess file, I'm trying to get the basic CodeIgniter mod_rewrite files working in my apache conf file. I'm doing this because apache says .htaccess files cause a performance hit.
Quote:You should avoid using .htaccess files completely if you have access to httpd main server config file. The mod_rewrite section of my apache conf, which is based on the default htaccess file, looks like this: Code: <IfModule mod_rewrite.c> Note that the www redirect is a bit different in my case due to different requirements. This mostly works, but for some reason it also rewrites all of my CSS/JS/images also despite the !-f and !-d rewrite conditions. Can anyone tell me how to modify this so that it prevents rewriting of actual files to the index.php file? (02-12-2021, 07:02 PM)kenjis Wrote: Debug mod_rewrite.Sadly, the debug information wasn't very informative. I amped up rewrite reporting to its maximum level, trace8, but the most telling lines don't tell you much: Code: [Fri Feb 12 12:42:22.201839 2021] [rewrite:trace2] [pid 48329:tid 140340508313344] mod_rewrite.c(483): [client 127.0.0.1:35566] 127.0.0.1 - - [www.example.com/sid#7fa393ce1ab0][rid#7fa39024f0a0/initial] init rewrite engine with requested uri /js/bootstrap.js I looked into the documentation and saw a curious (but also somewhat cryptic) bit information about REQUEST_FILENAME: Quote:The full local filesystem path to the file or script matching the request, if this has already been determined by the server at the time REQUEST_FILENAME is referenced. Otherwise, such as when used in virtual host context, the same value as REQUEST_URI. Depending on the value of AcceptPathInfo, the server may have only used some leading components of the REQUEST_URI to map the request to a file. Evidently, because I've got this rewrite stuff in the apache conf in a <VirtualHost> block, the server doesn't yet know exactly what the local file system path is. I visited the #apache IRC chat and a kind person there suggested putting %{DOCUMENT_ROOT} ahead of the %{REQUEST_FILENAME} for those vital lines and this has fixed the problem: Code: RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f This person on the apache IRC chat suggested eliminating mod_rewrite entirely and using FallbackResource instead. Code: FallbackResource /index.php
What does it tell you when you use the we browsers developer tools F12 ?
It could be a CORS problem. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(02-12-2021, 09:59 PM)InsiteFX Wrote: What does it tell you when you use the we browsers developer tools F12 ?the domain requests are all consistent. Every asset reference in the HTML is a relative reference. Attempting to access an asset directly was leading to 404. I.e., I'd just type this in the browser url bar and get 404: https://www.example.com/js/bootstrap.js To reiterate, the problem stems from the fact that I was putting my mod_rewrite rules in the apache conf rather than in the .htaccess file. In an .htaccess file, Apache knows what the local file system is. Apparently when these rules are evaluated in the apache conf, the local file system location has not yet been worked out by Apache so you must prepend %{DOCUMENT_ROOT} to %{REQUEST_FILENAME} for the main RewriteRule. |
Welcome Guest, Not a member yet? Register Sign In |