|
Alexander Sadleir
|
1 |
# Apache configuration file |
|
|
2 |
# httpd.apache.org/docs/2.2/mod/quickreference.html |
|
|
3 |
|
|
|
4 |
# Note .htaccess files are an overhead, this logic should be in your Apache config if possible |
|
|
5 |
# httpd.apache.org/docs/2.2/howto/htaccess.html |
|
|
6 |
|
|
|
7 |
# Techniques in here adapted from all over, including: |
|
|
8 |
# Kroc Camen: camendesign.com/.htaccess |
|
|
9 |
# perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/ |
|
|
10 |
# Sample .htaccess file of CMS MODx: modxcms.com |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
### |
|
|
14 |
### If you run a webserver other than apache, consider: |
|
|
15 |
### github.com/paulirish/html5-boilerplate-server-configs |
|
|
16 |
### |
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
# ---------------------------------------------------------------------- |
|
|
21 |
# Better website experience for IE users |
|
|
22 |
# ---------------------------------------------------------------------- |
|
|
23 |
|
|
|
24 |
# Force the latest IE version, in various cases when it may fall back to IE7 mode |
|
|
25 |
# github.com/rails/rails/commit/123eb25#commitcomment-118920 |
|
|
26 |
# Use ChromeFrame if it's installed for a better experience for the poor IE folk |
|
|
27 |
|
|
|
28 |
<IfModule mod_headers.c> |
|
|
29 |
Header set X-UA-Compatible "IE=Edge,chrome=1" |
|
|
30 |
# mod_headers can't match by content-type, but we don't want to send this header on *everything*... |
|
|
31 |
<FilesMatch "\.(js|css|gif|png|jpe?g|pdf|xml|oga|ogg|m4a|ogv|mp4|m4v|webm|svg|svgz|eot|ttf|otf|woff|ico|webp|appcache|manifest|htc|crx|xpi|safariextz|vcf)$" > |
|
|
32 |
Header unset X-UA-Compatible |
|
|
33 |
</FilesMatch> |
|
|
34 |
</IfModule> |
|
|
35 |
|
|
|
36 |
|
|
|
37 |
# ---------------------------------------------------------------------- |
|
|
38 |
# Cross-domain AJAX requests |
|
|
39 |
# ---------------------------------------------------------------------- |
|
|
40 |
|
|
|
41 |
# Serve cross-domain ajax requests, disabled. |
|
|
42 |
# enable-cors.org |
|
|
43 |
# code.google.com/p/html5security/wiki/CrossOriginRequestSecurity |
|
|
44 |
|
|
|
45 |
# <IfModule mod_headers.c> |
|
|
46 |
# Header set Access-Control-Allow-Origin "*" |
|
|
47 |
# </IfModule> |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
# ---------------------------------------------------------------------- |
|
|
52 |
# Webfont access |
|
|
53 |
# ---------------------------------------------------------------------- |
|
|
54 |
|
|
|
55 |
# Allow access from all domains for webfonts. |
|
|
56 |
# Alternatively you could only whitelist your |
|
|
57 |
# subdomains like "subdomain.example.com". |
|
|
58 |
|
|
|
59 |
<FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css)$"> |
|
|
60 |
<IfModule mod_headers.c> |
|
|
61 |
Header set Access-Control-Allow-Origin "*" |
|
|
62 |
</IfModule> |
|
|
63 |
</FilesMatch> |
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
# ---------------------------------------------------------------------- |
|
|
68 |
# Proper MIME type for all files |
|
|
69 |
# ---------------------------------------------------------------------- |
|
|
70 |
|
|
|
71 |
|
|
|
72 |
# JavaScript |
|
|
73 |
# Normalize to standard type (it's sniffed in IE anyways) |
|
|
74 |
# tools.ietf.org/html/rfc4329#section-7.2 |
|
|
75 |
AddType application/javascript js |
|
|
76 |
|
|
|
77 |
# Audio |
|
|
78 |
AddType audio/ogg oga ogg |
|
|
79 |
AddType audio/mp4 m4a |
|
|
80 |
|
|
|
81 |
# Video |
|
|
82 |
AddType video/ogg ogv |
|
|
83 |
AddType video/mp4 mp4 m4v |
|
|
84 |
AddType video/webm webm |
|
|
85 |
|
|
|
86 |
# SVG. |
|
|
87 |
# Required for svg webfonts on iPad |
|
|
88 |
# twitter.com/FontSquirrel/status/14855840545 |
|
|
89 |
AddType image/svg+xml svg svgz |
|
|
90 |
AddEncoding gzip svgz |
|
|
91 |
|
|
|
92 |
# Webfonts |
|
|
93 |
AddType application/vnd.ms-fontobject eot |
|
|
94 |
AddType application/x-font-ttf ttf ttc |
|
|
95 |
AddType font/opentype otf |
|
|
96 |
AddType application/x-font-woff woff |
|
|
97 |
|
|
|
98 |
# Assorted types |
|
|
99 |
AddType image/x-icon ico |
|
|
100 |
AddType image/webp webp |
|
|
101 |
AddType text/cache-manifest appcache manifest |
|
|
102 |
AddType text/x-component htc |
|
|
103 |
AddType application/x-chrome-extension crx |
|
|
104 |
AddType application/x-xpinstall xpi |
|
|
105 |
AddType application/octet-stream safariextz |
|
|
106 |
AddType text/x-vcard vcf |
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
# ---------------------------------------------------------------------- |
|
|
111 |
# Allow concatenation from within specific js and css files |
|
|
112 |
# ---------------------------------------------------------------------- |
|
|
113 |
|
|
|
114 |
# e.g. Inside of script.combined.js you could have |
|
|
115 |
# <!--#include file="libs/jquery-1.5.0.min.js" --> |
|
|
116 |
# <!--#include file="plugins/jquery.idletimer.js" --> |
|
|
117 |
# and they would be included into this single file. |
|
|
118 |
|
|
|
119 |
# This is not in use in the boilerplate as it stands. You may |
|
|
120 |
# choose to name your files in this way for this advantage or |
|
|
121 |
# concatenate and minify them manually. |
|
|
122 |
# Disabled by default. |
|
|
123 |
|
|
|
124 |
#<FilesMatch "\.combined\.js$"> |
|
|
125 |
# Options +Includes |
|
|
126 |
# AddOutputFilterByType INCLUDES application/javascript application/json |
|
|
127 |
# SetOutputFilter INCLUDES |
|
|
128 |
#</FilesMatch> |
|
|
129 |
#<FilesMatch "\.combined\.css$"> |
|
|
130 |
# Options +Includes |
|
|
131 |
# AddOutputFilterByType INCLUDES text/css |
|
|
132 |
# SetOutputFilter INCLUDES |
|
|
133 |
#</FilesMatch> |
|
|
134 |
|
|
|
135 |
|
|
|
136 |
# ---------------------------------------------------------------------- |
|
|
137 |
# Gzip compression |
|
|
138 |
# ---------------------------------------------------------------------- |
|
|
139 |
|
|
|
140 |
<IfModule mod_deflate.c> |
|
|
141 |
|
|
|
142 |
# Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/ |
|
|
143 |
<IfModule mod_setenvif.c> |
|
|
144 |
<IfModule mod_headers.c> |
|
|
145 |
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding |
|
|
146 |
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding |
|
|
147 |
</IfModule> |
|
|
148 |
</IfModule> |
|
|
149 |
|
|
|
150 |
# HTML, TXT, CSS, JavaScript, JSON, XML, HTC: |
|
|
151 |
<IfModule filter_module> |
|
|
152 |
FilterDeclare COMPRESS |
|
|
153 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html |
|
|
154 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css |
|
|
155 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain |
|
|
156 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml |
|
|
157 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component |
|
|
158 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript |
|
|
159 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json |
|
|
160 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml |
|
|
161 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml |
|
|
162 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml |
|
|
163 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml |
|
|
164 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject |
|
|
165 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml |
|
|
166 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf |
|
|
167 |
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype |
|
|
168 |
FilterChain COMPRESS |
|
|
169 |
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no |
|
|
170 |
</IfModule> |
|
|
171 |
|
|
|
172 |
<IfModule !mod_filter.c> |
|
|
173 |
# Legacy versions of Apache |
|
|
174 |
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json |
|
|
175 |
AddOutputFilterByType DEFLATE application/javascript |
|
|
176 |
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component |
|
|
177 |
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml |
|
|
178 |
AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype |
|
|
179 |
</IfModule> |
|
|
180 |
</IfModule> |
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
# ---------------------------------------------------------------------- |
|
|
185 |
# Expires headers (for better cache control) |
|
|
186 |
# ---------------------------------------------------------------------- |
|
|
187 |
|
|
|
188 |
# These are pretty far-future expires headers. |
|
|
189 |
# They assume you control versioning with cachebusting query params like |
|
|
190 |
# <script src="application.js?20100608"> |
|
|
191 |
# Additionally, consider that outdated proxies may miscache |
|
|
192 |
# www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ |
|
|
193 |
|
|
|
194 |
# If you don't use filenames to version, lower the CSS and JS to something like |
|
|
195 |
# "access plus 1 week" or so. |
|
|
196 |
|
|
|
197 |
<IfModule mod_expires.c> |
|
|
198 |
ExpiresActive on |
|
|
199 |
|
|
|
200 |
# Perhaps better to whitelist expires rules? Perhaps. |
|
|
201 |
ExpiresDefault "access plus 1 month" |
|
|
202 |
|
|
|
203 |
# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5) |
|
|
204 |
ExpiresByType text/cache-manifest "access plus 0 seconds" |
|
|
205 |
|
|
|
206 |
# Your document html |
|
|
207 |
ExpiresByType text/html "access plus 0 seconds" |
|
|
208 |
|
|
|
209 |
# Data |
|
|
210 |
ExpiresByType text/xml "access plus 0 seconds" |
|
|
211 |
ExpiresByType application/xml "access plus 0 seconds" |
|
|
212 |
ExpiresByType application/json "access plus 0 seconds" |
|
|
213 |
|
|
|
214 |
# Feed |
|
|
215 |
ExpiresByType application/rss+xml "access plus 1 hour" |
|
|
216 |
ExpiresByType application/atom+xml "access plus 1 hour" |
|
|
217 |
|
|
|
218 |
# Favicon (cannot be renamed) |
|
|
219 |
ExpiresByType image/x-icon "access plus 1 week" |
|
|
220 |
|
|
|
221 |
# Media: images, video, audio |
|
|
222 |
ExpiresByType image/gif "access plus 1 month" |
|
|
223 |
ExpiresByType image/png "access plus 1 month& |