Fixed – Browser Cache in .htaccess Generating 500 Internal Server Error

Posted on

Implementing browser cache is the most important factor to speed up your website. Browser cache working on client side, it will cache static component of the webpage in client browser. By doing this client browser will only request necessary component thus reducing request and speed up the process of displaying webpage on client computer.
To achieve this you can use cache plugin if you are using WordPress or add the code directly to .htaccess file

This time I want to share my experience adding browser cache code into .htaccess file got 500 Internal Server Error and how i manage to fixed it.

I was edit .htaccess file directly from file manager in CPANEL because for me much simpler and faster compared to using FTP client software.

After I add the cache code into my .htaccess file, my website is not accessible with error 500 Internal Server. This is bad and i want to revert it to the condition before I modify the file. Luckily I made the backup for .htaccess file so restoring to previous state is easy.

After testing and testing i found that the code may have errors, so i browse in the internet to get the correct code for browser cache.

Finally i got the correct and working code from gtmetrix, the code is:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg “access plus 1 year”
ExpiresByType image/jpeg “access plus 1 year”
ExpiresByType image/gif “access plus 1 year”
ExpiresByType image/png “access plus 1 year”
ExpiresByType text/css “access plus 1 month”
ExpiresByType application/pdf “access plus 1 month”
ExpiresByType text/x-javascript “access plus 1 month”
ExpiresByType application/x-shockwave-flash “access plus 1 month”
ExpiresByType image/x-icon “access plus 1 year”
ExpiresDefault “access plus 2 days”
</IfModule>
## EXPIRES CACHING ##

I just copy and pas the code above and it work perfectly without 500 Internal Server error. If you want more  detail explanation you can find the source here https://gtmetrix.com/leverage-browser-caching.html

 

 

 

Facebook Comments