Welcome Guest, Not a member yet? Register   Sign In
apache mod_rewrite problem: all css/js/images 404
#3

(02-12-2021, 07:02 PM)kenjis Wrote: Debug mod_rewrite.
https://stackoverflow.com/questions/9632...od-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
[Fri Feb 12 12:42:22.201851 2021] [rewrite:trace3] [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] applying pattern '^(.*)/$' to uri '/js/bootstrap.js'
[Fri Feb 12 12:42:22.201860 2021] [rewrite:trace3] [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] applying pattern '^(.*)$' to uri '/js/bootstrap.js'
[Fri Feb 12 12:42:22.201870 2021] [rewrite:trace4] [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] RewriteCond: input='www.example.com' pattern='^example\\.com$' [NC] => not-matched
[Fri Feb 12 12:42:22.201876 2021] [rewrite:trace3] [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] applying pattern '^(.*)$' to uri '/js/bootstrap.js'
[Fri Feb 12 12:42:22.201887 2021] [rewrite:trace4] [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] RewriteCond: input='/js/bootstrap.js' pattern='!-f' => matched
[Fri Feb 12 12:42:22.201895 2021] [rewrite:trace4] [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] RewriteCond: input='/js/bootstrap.js' pattern='!-d' => matched
[Fri Feb 12 12:42:22.201901 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] rewrite '/js/bootstrap.js' -> '/index.php/js/bootstrap.js'
[Fri Feb 12 12:42:22.201907 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] local path result: /index.php/js/bootstrap.js
[Fri Feb 12 12:42:22.201924 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] prefixed with document_root to /var/www/example/public/index.php/js/bootstrap.js
[Fri Feb 12 12:42:22.201933 2021] [rewrite:trace1] [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] go-ahead with /var/www/example/public/index.php/js/bootstrap.js [OK]

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
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php$1 [L,NC,QSA]

This person on the apache IRC chat suggested eliminating mod_rewrite entirely and using FallbackResource instead.
Code:
FallbackResource /index.php
Reply


Messages In This Thread
RE: apache mod_rewrite problem: all css/js/images 404 - by sneakyimp - 02-12-2021, 07:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB