Add a .htaccess File to a Jekyll Site
Apache, Jekyll, Performance
Adding a .htaccess
file to your document root allows fine control over access permissions.
Amongst other things, .htaccess
rules can set:
- In-browser caching
- Access - you could allow/disallow access from certain IP addresses or ranges
- Redirects
- Rewrites
You can also prevent modification of code over 3G on some European providers (I’ve experienced UK providers in particular totally mangling site styles).
When setting up WordPress sites, we would typically lock down access to the entire admin area by IP address as a security measure. While this isn’t necessary for Jekyll sites (where there is no login), .htaccess rules can be a useful way of controlling how your site resources are cached.
A proper .htaccess thereby has the potential to speed up site loading times.
##.htaccess in Jekyll By default Jekyll excludes dotfiles - but you can easily override this behaviour:
In config.yml
(or config_prod.yml
if you have a production environment config file):
Jekyll will now build the .htaccess
file - which is much more convenient than editing the file on the server.
Add the .htaccess file to the root of your Jekyll project
Sample .htaccess for Cache Control
comments powered by Disqus