Reputation: 1167
I've checked my plesk control panel on my vps and those mods are installed but when I run the site through http://redbot.org/ to check what's being sent, I get:
This response is negotiated, but doesn't have an appropriate Vary header.
The max-age Cache-Control directive appears more than once.
Cache-Control: no-cache, max-age=0, must-revalidate, no-transform, max-age=300
So it doesn't look like it's working.
Here's the .htaccess that I edited:
### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files web.config>
Order deny,allow
Deny from all
</Files>
# This denies access to all yml files, since developers might include sensitive
# information in them. See the docs for work-arounds to serve some yaml files
<Files *.yml>
Order allow,deny
Deny from all
</Files>
# Define some expiry header settings.
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 5 minutes"
ExpiresByType image/gif "access plus 7 day"
ExpiresByType image/png "access plus 7 day"
ExpiresByType image/jpg "access plus 7 day"
ExpiresByType image/jpeg "access plus 7 day"
ExpiresByType image/ico "access plus 7 day"
ExpiresByType text/css "access plus 7 day"
ExpiresByType text/javascript "access plus 7 day"
ExpiresByType application/x-javascript "access plus 7 day"
</IfModule>
# Append the 'Vary: Accept-Encoding' for resources that might need it.
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
RewriteBase '/'
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule .* framework/main.php?url=%1&%{QUERY_STRING} [L]
</IfModule>
### SILVERSTRIPE END ###
I'm just trying to add a little client-side caching to my site and I was also advised to add the old Vary:Accept-Encoding for clients that can't handle gzip - apparently it's best practice to.
Any ideas where I'm going wrong here?
Upvotes: 0
Views: 5324
Reputation: 2069
You can login as root to your server and run something like the 2 lines below (which might be a bit different depending on your server's config, apache version etc)
a2enmod expires
a2enmod headers
Then simply restart your Apache server:
systemctl restart apache2
or
service httpd restart
The above example works on Ubuntu 20.04 Server, running Virtualmin as a hosting solution. (tested myself)
For other installations, apache versions simply google: "a2enmod expires" on CentOS 7, Apache version 1
Upvotes: 2
Reputation: 174
Your htaccess file has
<IfModule mod_expires.c>
It may be that your VPS doesn't have the mod_expires installed for apache. If that is the case then it would make sense that the expires configuration wouldn't get applied.
Upvotes: 2