Skip to content

Commit b4e8a5a

Browse files
author
Paul Robert Lloyd
committed
Add server performance rules
1 parent 383e1f5 commit b4e8a5a

File tree

1 file changed

+144
-41
lines changed

1 file changed

+144
-41
lines changed

.htaccess

+144-41
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,151 @@
1-
# Kirby .htaccess
2-
3-
# rewrite rules
1+
# ----------------------------------------------------------------------
2+
# Kirby URL rewrite rules
3+
# ----------------------------------------------------------------------
44
<IfModule mod_rewrite.c>
5+
RewriteEngine on
6+
RewriteBase /
7+
8+
# Block text files in the content folder from being accessed directly
9+
RewriteRule ^content/(.*)\.(txt|md|mdown)$ error [R=301,L]
10+
11+
# Block all files in the site folder from being accessed directly
12+
RewriteRule ^site/(.*) error [R=301,L]
13+
14+
# Block all files in the kirby folder from being accessed directly
15+
RewriteRule ^kirby/(.*) error [R=301,L]
16+
17+
# Make panel links work
18+
RewriteCond %{REQUEST_FILENAME} !-f
19+
RewriteCond %{REQUEST_FILENAME} !-d
20+
RewriteRule ^panel/(.*) panel/index.php [L]
21+
22+
# Make site links work
23+
RewriteCond %{REQUEST_FILENAME} !-f
24+
RewriteCond %{REQUEST_FILENAME} !-d
25+
RewriteRule ^(.*) index.php [L]
26+
</IfModule>
27+
28+
29+
# ----------------------------------------------------------------------
30+
# UTF-8 Encoding
31+
# ----------------------------------------------------------------------
32+
# Use utf-8 encoding for anything served text/plain or text/html
33+
AddDefaultCharset utf-8
34+
35+
# Force utf-8 for a number of file formats
36+
AddCharset utf-8 .html .php .css .js .xml .json .rss
37+
38+
39+
# ----------------------------------------------------------------------
40+
# PHP Settings
41+
# ----------------------------------------------------------------------
42+
# Use php5
43+
AddHandler php5-script .php
44+
45+
# Don't allow PHP short tags
46+
php_flag short_open_tag on
47+
48+
# Close a major security hole that is abused by most XSS attacks
49+
php_flag register_globals Off
50+
551

6-
# enable awesome urls. i.e.:
7-
# http://yourdomain.com/about-us/team
8-
RewriteEngine on
9-
10-
# make sure to set the RewriteBase correctly
11-
# if you are running the site in a subfolder.
12-
# Otherwise links or the entire site will break.
13-
#
14-
# If your homepage is http://yourdomain.com/mysite
15-
# Set the RewriteBase to:
16-
#
17-
# RewriteBase /mysite
18-
#
19-
RewriteBase /
20-
21-
# block text files in the content folder from being accessed directly
22-
RewriteRule ^content/(.*)\.(txt|md|mdown)$ error [R=301,L]
23-
24-
# block all files in the site folder from being accessed directly
25-
RewriteRule ^site/(.*) error [R=301,L]
26-
27-
# block all files in the kirby folder from being accessed directly
28-
RewriteRule ^kirby/(.*) error [R=301,L]
29-
30-
# make panel links work
31-
RewriteCond %{REQUEST_FILENAME} !-f
32-
RewriteCond %{REQUEST_FILENAME} !-d
33-
RewriteRule ^panel/(.*) panel/index.php [L]
34-
35-
# make site links work
36-
RewriteCond %{REQUEST_FILENAME} !-f
37-
RewriteCond %{REQUEST_FILENAME} !-d
38-
RewriteRule ^(.*) index.php [L]
39-
52+
# ----------------------------------------------------------------------
53+
# Better website experience for IE users
54+
# ----------------------------------------------------------------------
55+
# Force the latest IE version, in various cases when it may fall back to IE7 mode
56+
# Use ChromeFrame if it's installed for a better experience for the poor IE folk
57+
58+
<IfModule mod_headers.c>
59+
Header set X-UA-Compatible "IE=Edge,chrome=1"
60+
<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)$" >
61+
# mod_headers can't match by content-type, but we don't want to send this header on everything...
62+
Header unset X-UA-Compatible
63+
</FilesMatch>
64+
</IfModule>
65+
66+
67+
# ----------------------------------------------------------------------
68+
# Proper MIME type for all files
69+
# ----------------------------------------------------------------------
70+
# Images
71+
AddType image/x-icon ico
72+
AddType image/webp webp
73+
AddType image/svg+xml svg
74+
75+
# Other
76+
AddType application/javascript js
77+
AddType application/atom+xml xml
78+
AddType application/opensearchdescription+xml xml
79+
AddType text/cache-manifest appcache manifest
80+
81+
82+
# ----------------------------------------------------------------------
83+
# Performance
84+
# ----------------------------------------------------------------------
85+
<IfModule mod_headers.c>
86+
# FileETag None is not enough for every server.
87+
Header unset ETag
4088
</IfModule>
4189

90+
# Since we're sending far-future expires, we don't need ETags for static content.
91+
FileETag None
92+
93+
<IfModule mod_expires.c>
94+
# Set expires headers
95+
ExpiresActive on
96+
97+
# Perhaps better to whitelist expires rules? Perhaps.
98+
ExpiresDefault "access plus 1 month"
99+
100+
# HTML
101+
ExpiresByType text/html "access plus 10 minutes"
102+
103+
# Data
104+
ExpiresByType text/xml "access plus 0 seconds"
105+
ExpiresByType application/xml "access plus 0 seconds"
106+
ExpiresByType application/json "access plus 0 seconds"
107+
108+
# RSS feeds
109+
ExpiresByType application/rss+xml "access plus 1 hour"
110+
ExpiresByType application/atom+xml "access plus 1 hour"
111+
112+
# Favicon (cannot be renamed)
113+
ExpiresByType image/x-icon "access plus 1 month"
114+
115+
# Images
116+
ExpiresByType image/gif "access plus 1 month"
117+
ExpiresByType image/png "access plus 1 month"
118+
ExpiresByType image/jpeg "access plus 1 month"
119+
120+
# CSS and JavaScript
121+
# ExpiresByType text/css "access plus 2 months"
122+
# ExpiresByType application/javascript "access plus 2 months"
123+
</IfModule>
42124

43-
# Additional recommended values
44-
# Remove comments for those you want to use.
45125

46-
AddDefaultCharset UTF-8
126+
# ----------------------------------------------------------------------
127+
# GZIP Compression
128+
# ----------------------------------------------------------------------
129+
<IfModule mod_deflate.c>
130+
# Force deflate for mangled headers
131+
<IfModule mod_setenvif.c>
132+
<IfModule mod_headers.c>
133+
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
134+
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
135+
</IfModule>
136+
</IfModule>
47137

48-
php_flag short_open_tag on
138+
# Compress all output labeled with one of the following MIME-types
139+
AddOutputFilterByType DEFLATE application/atom+xml \
140+
application/javascript \
141+
application/json \
142+
application/rss+xml \
143+
application/xhtml+xml \
144+
application/xml \
145+
image/svg+xml \
146+
image/x-icon \
147+
text/css \
148+
text/html \
149+
text/plain \
150+
text/xml
151+
</IfModule>

0 commit comments

Comments
 (0)