1

We recently moved an old PHP Project from a server using httpd to our regular prod. servers running apache2. In this project we have some reroute 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 404's.

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

For CSS and Image Files meanwhile it does more work:

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

EDIT: 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.domain.de/sid#7f7d13fd2cb8] init rewrite engine with requested uri /javascript/jquery-1.11.1.min.js
[rewrite:trace1] mod_rewrite.c(476): [sub.domain.de/sid#7f7d13fd2cb8] pass through /javascript/jquery-1.11.1.min.js

migrated from superuser.com May 29 at 13:25

This question came from our site for computer enthusiasts and power users.

  • "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 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 at 14:41
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.

  • "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 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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