mod_expires through htaccess gives 505 error

September 29, 2014 1.5k views

I'm running a site with Apache and I want to use modexpires in my htaccess file for better performance. For some reason, including anything inside the <IfModule modexpires.c> block gives me a 505 server error. I've checked the server config making sure mod_expires is installed and enabled, and I also changed the apache2.conf file so that I can override settings with htaccess.

This is what my mod_expires block looks like,

<IfModule mod_expires.c>
    ExpiresActive on
    #ExpiresDefault                                      "access plus 1 month"

  # CSS
    ExpiresByType text/css                              "access plus 1 year"

  # Data interchange
    ExpiresByType application/json                      "access plus 0 seconds"
    ExpiresByType application/xml                       "access plus 0 seconds"
    ExpiresByType text/xml                              "access plus 0 seconds"

  # Favicon (cannot be renamed!)
    ExpiresByType image/x-icon                          "access plus 1 week"

  # HTML components (HTCs)
    ExpiresByType text/x-component                      "access plus 1 month"

  # HTML
    ExpiresByType text/html                             "access plus 0 seconds"

  # JavaScript
    ExpiresByType application/javascript                "access plus 1 year"

  # Manifest files
    ExpiresByType application/x-web-app-manifest+json   "access plus 0 seconds"
    ExpiresByType text/cache-manifest                   "access plus 0 seconds"

  # Media
    ExpiresByType audio/ogg                             "access plus 1 month"
    ExpiresByType image/gif                             "access plus 1 month"
    ExpiresByType image/jpeg                            "access plus 1 month"
    ExpiresByType image/png                             "access plus 1 month"
    ExpiresByType video/mp4                             "access plus 1 month"
    ExpiresByType video/ogg                             "access plus 1 month"
    ExpiresByType video/webm                            "access plus 1 month"

  # Web feeds
    ExpiresByType application/atom+xml                  "access plus 1 hour"
    ExpiresByType application/rss+xml                   "access plus 1 hour"

  # Web fonts
    ExpiresByType application/font-woff                 "access plus 1 month"
    ExpiresByType application/         "access plus 1 month"
    ExpiresByType application/x-font-ttf                "access plus 1 month"
    ExpiresByType font/opentype                         "access plus 1 month"
    ExpiresByType image/svg+xml                         "access plus 1 month"

Any ideas?
Running the WordPress One-Click VPS setup.

1 comment
  • Do you see any errors in Apache's error log? What's the output of:

    sudo tail -30 /var/log/apache2/error.log
2 Answers

Last line says "/var/www/.htaccess: ExpiresActive not allowed here", but I did just set that in the apache2.conf. Anywhere else I'd need to put this?

Never mind, solved it now. I put the Override All in the wrong place in Apache's config.

Have another answer? Share your knowledge.