Including .htaccess in Jekyll
The issue.
Jekyll doesn’t like files that begin with a dot. It’s understandable. Most of these files (like .gitignore
and .sass-cache
files) are not ones you typically want to deploy to a production server.
However, if you’re pushing up to an Apache server it’s likely you’ll want to use a .htaccess
file at some point. When I was initially setting up this website, this really threw me for a loop. I need that file! Apparently I’m not the only one.
The workaround.
Finally I came across this issue discussion in GitHub. Juev to the rescue.
Just create a file and tell Jekyll to change the name of the generated file. So simple!
In my project root, I have a file called htaccess
(no preceding dot) that contains:
---
layout: none
permalink: .htaccess
---
RewriteEngine On
RewriteCond %{http_host} ^www.newbieonruby.com [nc]
RewriteRule ^(.*)$ http://newbieonruby.com/$1 [r=301,nc]
All set! Now when I run my Jekyll command, a nice pretty .htaccess
file will show up.