Skip to content

Instantly share code, notes, and snippets.

@zdenekdrahos
Last active June 8, 2016 10:38
Show Gist options
  • Save zdenekdrahos/c903f50761cf41b17751 to your computer and use it in GitHub Desktop.
Save zdenekdrahos/c903f50761cf41b17751 to your computer and use it in GitHub Desktop.
Generate .htaccess in Middleman. https://coderwall.com/p/daflfq
# disable layout
page ".htaccess.apache", :layout => false
# rename file after build
after_build do
File.rename 'build/.htaccess.apache', 'build/.htaccess'
end
# MOVE PERMANENTLY
<% data.htaccess.redirect.each do |old, new| %>
Redirect 301 <%= old %> <%= data.htaccess.web.url %><%= new %>
<% end %>
# REWRITE - redirect to www. page
RewriteEngine on
RewriteCond %{HTTP_HOST} ^<%= data.htaccess.web.domain %>$
RewriteRule (.*) <%= data.htaccess.web.url %>/$1 [R=301,L]
# ERROR DOCUMENTS
<% data.htaccess.errors.each do |code, document| %>
ErrorDocument <%= code %> <%= document %>
<% end %>
# GZIP, CACHE
AddType image/x-icon .ico
ExpiresActive on
<% data.htaccess.cache.expire.each do |type, expire| %>
ExpiresByType <%= type %> "<%= expire %>"
<% end %>
<FilesMatch "<%= data.htaccess.cache.deflate %>">
SetOutputFilter DEFLATE
</FilesMatch>
web:
domain: example.com
url: http://www.example.com
redirect:
/old-url.html: /new-url.html
/another/url.html: /new/
/old-directory/: /new-directory/
cache:
deflate: \\.(js|css|html|ico|png)$
expire:
image/png: access plus 1 month
image/ico: access plus 1 month
image/x-icon: access plus 1 month
text/html: access plus 1 minute
text/css: access plus 7 days
application/javascript: access plus 7 days
text/javascript: access plus 7 days
errors:
401: "Unauthorized access"
404: /404.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment