forked from fhoech/gz.php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.htaccess
More file actions
112 lines (102 loc) · 4.13 KB
/
.htaccess
File metadata and controls
112 lines (102 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Minimal .htaccess file containing just the rules for gz.php and serving
# static .gz/.min files
# Turn on rewrite engine
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
</IfModule>
# BEGIN GZIP
# Force content type for known extensions
<FilesMatch "\.css\.(gz|min)$">
ForceType text/css
</FilesMatch>
<FilesMatch "\.html?\.gz$">
ForceType text/html
</FilesMatch>
<FilesMatch "\.ico\.gz$">
ForceType image/x-icon
</FilesMatch>
<FilesMatch "\.js\.(gz|min)$">
ForceType application/javascript
</FilesMatch>
<FilesMatch "\.json\.gz$">
ForceType application/json
</FilesMatch>
<FilesMatch "\.svg\.gz$">
ForceType image/svg+xml
</FilesMatch>
<FilesMatch "\.txt\.gz$">
ForceType text/plain
</FilesMatch>
<FilesMatch "\.xml\.gz$">
ForceType application/xml
</FilesMatch>
<FilesMatch "\.xsl\.gz$">
ForceType application/xslt+xml
</FilesMatch>
# Set 'Vary' response header for .gz files and files that can be compressed
<FilesMatch "\.(gz|min|css|html?|ico|js|json|svg|txt|xml|xsl)$">
<IfModule mod_headers.c>
Header always append Vary "Accept-Encoding"
</IfModule>
</FilesMatch>
# Set encoding for .gz files
<IfModule mod_mime.c>
# http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addencoding:
# "To make this long story short, you should always use x-gzip and x-compress
# for these two specific encodings"
AddEncoding x-gzip .gz
</IfModule>
<IfModule mod_rewrite.c>
# STATIC CACHING, gzip-encoded file next to original
# ONLY uncomment this if you plan to MANUALLY delete cached *.gz files
# after originals are changed!
#RewriteCond %{REQUEST_URI} \.(css|html?|ico|js|json|svg|txt|xml|xsl)$
## If the user agent accepts gzip encoding...
#RewriteCond %{HTTP:Accept-Encoding} gzip
## ...and if gzip-encoded version of the requested file exists (<file>.gz)...
#RewriteCond %{REQUEST_FILENAME}.gz -f
## ...then serve the gzip-encoded file. Done.
#RewriteRule ^ %{REQUEST_URI}.gz [L]
# STATIC CACHING, gzip-encoded file in gz-cache folder
# ONLY uncomment this if you plan to MANUALLY delete cached *.gz files
# after originals are changed!
#RewriteCond %{REQUEST_URI} \.(css|html?|ico|js|json|svg|txt|xml|xsl)$
## If the user agent accepts gzip encoding...
#RewriteCond %{HTTP:Accept-Encoding} gzip
## ...and if gzip-encoded version of the requested file exists (<file>.gz)...
#RewriteCond %{DOCUMENT_ROOT}/gz-cache%{REQUEST_URI}.gz -f
## ...then serve the gzip-encoded file. Done.
#RewriteRule ^ /gz-cache%{REQUEST_URI}.gz [L]
# DYNAMIC CACHING. NEVER COMMENT THIS OUT!
RewriteCond %{REQUEST_URI} \.(css|html?|ico|js|json|svg|txt|xml|xsl)$
# If the user agent accepts gzip encoding...
RewriteCond %{HTTP:Accept-Encoding} gzip
# ...and the requested file exists...
RewriteCond %{REQUEST_FILENAME} -f
# ...then use a PHP script to serve a compressed version. Done.
RewriteRule ^ /gz.php [L,E=REQUEST_URI:%{REQUEST_URI}]
# STATIC CACHING (MINIFICATION ONLY), minified file next to original
# ONLY uncomment this if you plan to MANUALLY delete cached *.min files
# after originals are changed!
#RewriteCond %{REQUEST_URI} \.(css|js)$
## If a minified version of the requested file exists (<file>.min)...
#RewriteCond %{REQUEST_FILENAME}.min -f
## ...then serve the minified file. Done.
#RewriteRule ^ %{REQUEST_URI}.min [L]
# STATIC CACHING (MINIFICATION ONLY), minified file in gz-cache folder
# ONLY uncomment this if you plan to MANUALLY delete cached *.min files
# after originals are changed!
#RewriteCond %{REQUEST_URI} \.(css|js)$
## If a minified version of the requested file exists (<file>.min)...
#RewriteCond %{DOCUMENT_ROOT}/gz-cache%{REQUEST_URI}.min -f
## ...then serve the minified file. Done.
#RewriteRule ^ /gz-cache%{REQUEST_URI}.min [L]
# DYNAMIC CACHING (MINIFICATION ONLY)
RewriteCond %{REQUEST_URI} \.(css|js)$
# Or if the requested file exists...
RewriteCond %{REQUEST_FILENAME} -f
# ...then use a PHP script serve a minified version. Done.
RewriteRule ^ /gz.php [L,E=REQUEST_URI:%{REQUEST_URI}]
</IfModule>
# END GZIP