1

We recently moved an old PHP Project from a server using httpd to our regular production servers running Apache2. In this project we have some rewrite rules that map requests either to our index.php file or if they are files they are supposed to be mapped into the public directory where static assets lie.

# Map request to index.php if the file was not found
# ---------------------------------------------------------------------------------------------
RewriteRule ^([a-z0-9\-/]*)$ public/index.php?morrow_path_info=$1&morrow_basehref_depth=1 [L,QSA,NC]

# Map all requests to the public subfolder (also features public folder)
# ---------------------------------------------------------------------------------------------
RewriteCond %{REQUEST_URI} !-f
RewriteRule features/(.+)/public/(.+) app/features/$1/public/$2 [L,QSA]

RewriteCond %{REQUEST_URI} !public
RewriteRule ^(.+)$ public/$1 [L,QSA]

These are all the rewrite rules in the .htaccess file and they are working fine for CSS, Images and the like, but all our JavaScript just passes through and hits 404s.

I already tried debugging by enabling logging for the reroute module and for JS files it spits out for example:

[rewrite:trace2] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] init rewrite engine with requested uri /javascript/bootstrap-datepicker.js, referer: https://sub.example.de/login
[rewrite:trace3] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] applying pattern '^(.*)$' to uri '/javascript/bootstrap-datepicker.js', referer: https://sub.example.de/login
[rewrite:trace1] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] pass through /javascript/bootstrap-datepicker.j , referer: https://sub.example.de/login

For CSS and Image Files meanwhile it does more work:

[rewrite:trace2] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] init rewrite engine with requested uri /public/fonts/fontawesome-webfont.woff2, referer: https://sub.example.de/css/font-awesome.min.css
[rewrite:trace3] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] applying pattern '^(.*)$' to uri '/public/fonts/fontawesome-webfont.woff2', referer: https://sub.example.de/css/font-awesome.min.css
[rewrite:trace1] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] pass through /public/fonts/fontawesome-webfont.woff2, referer: https://sub.example.de/css/font-awesome.min.css
[rewrite:trace3] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] [perdir /var/www/git/sub.example.de/] strip per-dir prefix: /var/www/git/sub.example.de/public/fonts/fontawesome-webfont.woff2 -> public/fonts/fontawesome-webfont.woff2, referer: https://sub.example.de/css/font-awesome.min.css
[rewrite:trace3] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] [perdir /var/www/git/sub.example.de/] applying pattern '^([a-z0-9\\-/]*)$' to uri 'public/fonts/fontawesome-webfont.woff2', referer: https://sub.example.de/css/font-awesome.min.css
[rewrite:trace3] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] [perdir /var/www/git/sub.example.de/] strip per-dir prefix: /var/www/git/sub.example.de/public/fonts/fontawesome-webfont.woff2 -> public/fonts/fontawesome-webfont.woff2, referer: https://sub.example.de/css/font-awesome.min.css
[rewrite:trace3] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] [perdir /var/www/git/sub.example.de/] applying pattern 'features/(.+)/public/(.+)' to uri 'public/fonts/fontawesome-webfont.woff2', referer: https://sub.example.de/css/font-awesome.min.css
[rewrite:trace3] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] [perdir /var/www/git/sub.example.de/] strip per-dir prefix: /var/www/git/sub.example.de/public/fonts/fontawesome-webfont.woff2 -> public/fonts/fontawesome-webfont.woff2, referer: https://sub.example.de/css/font-awesome.min.css
[rewrite:trace3] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] [perdir /var/www/git/sub.example.de/] applying pattern '^(.+)$' to uri 'public/fonts/fontawesome-webfont.woff2', referer: https://sub.example.de/css/font-awesome.min.css
[rewrite:trace1] mod_rewrite.c(476): [sub.example.de/sid#7f7d14046cb8] [perdir /var/www/git/sub.example.de/] pass through /var/www/git/sub.example.de/public/fonts/fontawesome-webfont.woff2, referer: https://sub.example.de/css/font-awesome.min.css

So it seems like for JavaScript files once they fail the first condition (as they should) it just skips the rest of the rules. The VHost Configuration for this domain also has nothing beside DocRoot, ErrorLog Locations, SSL and the usual:

RewriteEngine On
<Directory /var/www/git/sub.example.de/>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

I have since found out that the 1 Rewrite that applied to .js files was actually global. So .js files still completely ignore the .htaccess file in it's entirety, just spitting pass through into the rewrite log.

[rewrite:trace2] mod_rewrite.c(476): [sub.example.de/sid#7f7d13fd2cb8] init rewrite engine with requested uri /javascript/jquery-1.11.1.min.js
[rewrite:trace1] mod_rewrite.c(476): [sub.example.de/sid#7f7d13fd2cb8] pass through /javascript/jquery-1.11.1.min.js
2
  • "applying pattern '^(.*)$'" - Where is the directive that contains this pattern? You mention, that it "was actually global." - what do you mean by this? Where? And what directive is this? A significant difference with the CSS log output is that the CSS file request appears to already have the /public prefix? Do you have any other .htaccess files? Perhaps in the /javascript subdirectory?
    – MrWhite
    May 29, 2019 at 14:39
  • Your first directive states: "Map request to index.php if the file was not found", but it does not explicitly check that the request does not map to a file (although the regex may exclude this), however, this directive would seem to catch requests that would ordinarily be handled by the second rule - is that intentional?
    – MrWhite
    May 29, 2019 at 14:41

1 Answer 1

1

Alright time to answer my own question after a long day of 2 people staring at this problem and being astounded.

As it turns out it was totally our fault, for someone in the land before the land before time (2013) had created a global configuration file which contained a most curious line:

alias /javascript /usr/share/javascript

One may make some curious guesses as to the purpose of this, but let it suffice to say this config file has been removed and with it the problem. This also explains why in the rewrite log it said that .js files just pass through. Aliases completely ignore the rewrite system.

1
  • "This also explains why in the rewrite log it said that js files just pass through." - That "pass through" relates specifically to whatever mod_rewrite directive was being executed, not this Alias. "Aliases completely ignore the rewrite system." - Aliases don't necessarily "ignore the rewrite system". The result of this Alias is that it would have most probably bypassed the .htaccess file in its entirety. The reason for this Alias looks like it would have been to have a common repository for JS files that could be shared between several sites (on the same server).
    – MrWhite
    May 29, 2019 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.