0
votes

I noticed, that when we request a static resource, i.e. like this: GET /MYAPP/css/navbar.css

it appears in apache logs as two lines:

[20/Jul/2015:11:39:07 -0400] 10.72.123.1 TLSv1 AES256-SHA "GET /MYAPP/css/navbar.css HTTP/1.1" 302 224 0/159

[20/Jul/2015:11:39:07 -0400] 10.72.123.1 TLSv1 AES256-SHA "GET /css/navbar.css HTTP/1.1" 200 2846 0/364

This is something to do with a current rewrite rule set up in the configs:

RewriteRule ^/MYAPP/css/(.*)$ https://%{SERVER_NAME}/css/$1
...
<Directory "/var/www/myapp-static">
  Options None
  AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Am I right that's something is wrong here? Each request to a static file results in two calls instead of one, does it decrease the apache overall perforamnce in any way? Whats the best practice to handle this? As one of the solutions I see we can use links to static resources as /css/navbar.css directly, not via /MYAPP/css/navbar.css. But this will fail the application if it runs with no apache (as we do have some environments having no apache in it). Whats the best and typical solution is here?

1
Is the value of %{SERVER_NAME} different from the host name ? - Zimmi
@Zimmi I don't know to be honest.. how can I check the value of SERVER_NAME? Does it has something to do with a property ServerName defined inside the <VirtualHost> ? - javagirl
@Zimmi actually it must be! ServerName in the VirtualHost is defined as loadbalanced domain name, while host can be different. So they should be the same?? - javagirl

1 Answers

1
votes

If your %{SERVER_NAME} inside of the rule

RewriteRule ^/MYAPP/css/(.*)$ https://%{SERVER_NAME}/css/$1

is different from the host name, then Apache will make an external redirect, and write a log line, and a new request comes, that will be served. Many things can happen and depend on your setup, but my guess is now that you should give a try to a rule like this one:

RewriteRule ^/MYAPP/css/(.*)$ /css/$1

What I think could be the problem is described in the Apache doc about RewriteRule, where they describe "Substitution", paragraph "Absolute URL".

If you needed the rule also for the https, you could use environment variable %{HTTP_HOST} instead of %{SERVER_NAME}.