Last active
June 8, 2016 10:38
-
-
Save zdenekdrahos/c903f50761cf41b17751 to your computer and use it in GitHub Desktop.
Generate .htaccess in Middleman. https://coderwall.com/p/daflfq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# disable layout | |
page ".htaccess.apache", :layout => false | |
# rename file after build | |
after_build do | |
File.rename 'build/.htaccess.apache', 'build/.htaccess' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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