guh.me - gustavo's personal blog

htaccess for Jekyll 3

βΈ»

I’ve just updated my Jekyll setup from Jekyll 2.x to Jekyll 3.x. Apart from changing the highlighter setting to rouge, which is the new default syntax highlighter, I had to update my .htaccess file, since my blog is hosted on a shared Apache server.

By default, my Jekyll 2.x setup generated the blog posts as directories named as the post permalink; in 3.x, it changed to html files named as the post permalink. Because of that, I had to tweak my RewriteRule a little bit.

Options -Indexes
Options -FollowSymlinks
Options -MultiViews

RewriteEngine on
RewriteBase /

# Other rules
# ...

# Remove the .html extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9\-]+)\/?$ $1.html [NC,L]

In my RewriteRule, I’ve included an optional trailing slash, which matches the old links. It poses no SEO risks because Jekyll already includes the rel="canonical" tag.