-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path.htaccess
483 lines (341 loc) · 13.2 KB
/
.htaccess
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
#
# HTACCESS : useful tips & tricks
# uses a lot of good ideas from html5-boilerplate https://github.com/h5bp
# https://github.com/h5bp/server-configs-apache
#
# made by Nicolas (@nico3333fr)
# under WTFPL license
# no warranty: can’t be responsible for anything if you use it
# "great power involves great responsibility"
#
#
# ------------------------------------------------------------------------------
# | UTF-8 encoding |
# ------------------------------------------------------------------------------
<IfModule mod_mime.c>
AddCharset utf-8 .atom .scss .css .js .json .jsonld .rss .vtt .webapp .xml .txt .svg .webmanifest .html .htm .md
</IfModule>
# ------------------------------------------------------------------------------
# | Password protection |
# ------------------------------------------------------------------------------
#AuthUserFile /home/your_path/.htpasswd
#AuthGroupFile /dev/null
#AuthName " Restricted access "
#AuthType basic
#<Limit GET POST>
# Order Deny,Allow
# Deny From All
# Allow From 192.168.1.0/24
# require valid-user
# Satisfy Any
#</Limit>
# ------------------------------------------------------------------------------
# | Additionnal charset/types/etc. |
# ------------------------------------------------------------------------------
<IfModule mod_mime.c>
# Audio
AddType audio/mp4 m4a f4a f4b
AddType audio/mpeg mp3
AddType audio/ogg oga ogg opus
AddType audio/wav wav
AddType audio/webm webma
# Data interchange
AddType application/json json map
AddType application/ld+json jsonld
# JavaScript
# Normalize to standard type.
# http://tools.ietf.org/html/rfc4329#section-7.2
AddType application/javascript js
# Video
AddType video/mp4 f4v f4p m4v mp4
AddType video/ogg ogv
AddType video/webm webm
AddType video/x-flv flv
# Web fonts
AddType application/font-woff woff
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttc ttf
AddType application/x-font-woff woff
AddType application/font-woff2 .woff2
AddType font/opentype otf
# Make SVGZ fonts work on the iPad.
# https://twitter.com/FontSquirrel/status/14855840545
AddType image/svg+xml svgz
AddEncoding gzip svgz
# Other
AddType application/octet-stream safariextz
AddType application/x-chrome-extension crx
AddType application/x-opera-extension oex
AddType application/x-web-app-manifest+json webapp
AddType application/x-xpinstall xpi
AddType application/xml atom rdf rss xml
AddType image/webp webp
AddType image/x-icon cur
AddType image/vnd.microsoft.icon .ico
AddType text/cache-manifest appcache manifest
AddType text/css .css
AddType image/svg+xml svg
AddType text/vtt vtt
AddType text/x-component htc
AddType text/x-vcard vcf
AddType application/vnd.openxmlformats .docx .pptx .xlsx .xltx . xltm .dotx .potx .ppsx
AddType image/webp .webp
AddType application/manifest+json .webmanifest
</IfModule>
# ------------------------------------------------------------------------------
# | force download |
# ------------------------------------------------------------------------------
# for xslx
#<FilesMatch "\.(xlsx)$">
# ForceType application/octet-stream
# Header set Content-Disposition attachment
#</FilesMatch>
# ------------------------------------------------------------------------------
# | for uploadify or upload component |
# ------------------------------------------------------------------------------
#php_value max_execution_time 1800
#php_value upload_max_filesize 99M
#php_value post_max_size 99M
#php_value memory_limit 99M
#php_value max_input_time 3600
# for some strange cases/components, uncomment only if there is no other way
#<IfModule mod_security.c>
# SecFilterEngine Off
# SecFilterScanPOST Off
#</IfModule>
# ------------------------------------------------------------------------------
# | Custom error messages / pages |
# ------------------------------------------------------------------------------
# lost & found
ErrorDocument 404 /404.php
# niet
ErrorDocument 403 /403.php
# oops, internal server error
ErrorDocument 500 /500.php
# unauthorized
ErrorDocument 401 /401.php
# not implemented
#ErrorDocument 418 /418.php
# ------------------------------------------------------------------------------
# | File access |
# ------------------------------------------------------------------------------
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# no listing for directories
<IfModule mod_autoindex.c>
Options -Indexes
</IfModule>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# prevent accessing to all files excepted those mentionned (be careful to uppercase)
#<FilesMatch "(?<!\.png|\.jpg|\.gif|\.jpeg|\.svg|\.ico)$">
# Apache 2.2
# deny from all
# Apache 2.4
# Require all denied
#</FilesMatch>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# prevent executing PHP file in a folder
# Warning : do NEVER uncomment this in general htaccess, only in folders that need it !
#RemoveHandler .php .phtml .php3 .php4 .php5
#RemoveType .php .phtml .php3 .php4 .php5
#php_flag engine off
# To deny PHPs
#<Files ~ "\.(php3|php4|php5|phtml|pl|cgi)$">
# Apache 2.2
# deny from all
# Apache 2.4
# Require all denied
#</Files>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# block access to hidden files & directories
<IfModule mod_rewrite.c>
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule "(^|/)\." - [F]
</IfModule>
# ------------------------------------------------------------------------------
# | Rewrite engine |
# ------------------------------------------------------------------------------
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
# RewriteBase /
</IfModule>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# examples
<IfModule mod_rewrite.c>
# /page/plop?toto=tutu -> /page.php?page=plop&toto=tutu
# RewriteRule /pages/(.+) /page.php?page=$1 [QSA]
# my-ass -> my-ass.php
Options -MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
# sitemaps
#RewriteRule ^sitemap\.xml$ sitemap.php [L]
# security.txt
RewriteRule ^.well-known/security\.txt$ security.txt [L]
# to avoid 404 errors generated by iOS
# see http://www.creativejuiz.fr/blog/veille-technologique/ios-provoque-404-site-web-apple-touch-icon for reference
#RewriteRule ^apple-touch-icon-(.+)\.png apple-touch-icon.png [L]
# Cache busting for CSS/JS
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.+)_(\d+)\.(js|css)$ $1.$3 [L]
</IfModule>
# ------------------------------------------------------------------------------
# | Suppressing / Forcing the `www.` at the beginning of URLs |
# ------------------------------------------------------------------------------
# IMPORTANT: NEVER USE THESE RULES AT THE SAME TIME!
# UNCOMMENT THE GOOD ONE ONLY
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# HTTPS
# whatever, go to HTTPS
#<IfModule mod_rewrite.c>
# RewriteCond %{HTTPS} !=on
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#</IfModule>
# Option 1: rewrite www.example.com → example.com
#<IfModule mod_rewrite.c>
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteCond %{SERVER_ADDR} !=127.0.0.1
# RewriteCond %{SERVER_ADDR} !=::1
# RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
#</IfModule>
# Option 2: rewrite example.com → www.example.com
#<IfModule mod_rewrite.c>
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteCond %{SERVER_ADDR} !=127.0.0.1
# RewriteCond %{SERVER_ADDR} !=::1
# RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#</IfModule>
# Option 3: whatever → www.example.com
#<IfModule mod_rewrite.c>
# RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
# RewriteCond %{SERVER_ADDR} !=127.0.0.1
# RewriteCond %{SERVER_ADDR} !=::1
# RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
#</IfModule>
# HTTP
# Option 1: rewrite www.example.com → example.com
#<IfModule mod_rewrite.c>
# RewriteCond %{HTTPS} !=on
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
#</IfModule>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Option 2: rewrite example.com → www.example.com
#<IfModule mod_rewrite.c>
# RewriteCond %{HTTPS} !=on
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteCond %{SERVER_ADDR} !=127.0.0.1
# RewriteCond %{SERVER_ADDR} !=::1
# RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#</IfModule>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Option 3: whatever → www.example.com
#<IfModule mod_rewrite.c>
# RewriteCond %{HTTPS} !=on
# RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
# RewriteCond %{SERVER_ADDR} !=127.0.0.1
# RewriteCond %{SERVER_ADDR} !=::1
# RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L]
#</IfModule>
# ------------------------------------------------------------------------------
# | Compression |
# ------------------------------------------------------------------------------
<IfModule mod_deflate.c>
AddOutputFilter INCLUDES;DEFLATE js
AddOutputFilter INCLUDES;DEFLATE css
AddOutputFilter INCLUDES;DEFLATE php
AddOutputFilter INCLUDES;DEFLATE html
AddOutputFilter INCLUDES;DEFLATE xml
AddOutputFilter INCLUDES;DEFLATE ico
# webfonts
AddOutputFilter INCLUDES;DEFLATE eot
AddOutputFilter INCLUDES;DEFLATE svg
AddOutputFilter INCLUDES;DEFLATE ttf
# others
AddOutputFilter INCLUDES;DEFLATE vtt
AddOutputFilter INCLUDES;DEFLATE webmanifest
</IfModule>
# ------------------------------------------------------------------------------
# | Security |
# ------------------------------------------------------------------------------
# Stops a browser from trying to MIME-sniff
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
</IfModule>
# Avoid Clickjacking and enable XSS-protection for browsers
<FilesMatch "\.(pl|php|cgi|spl)$">
<IfModule mod_headers.c>
# security
Header set X-Frame-Options "DENY"
Header set X-XSS-Protection "1; mode=block"
</IfModule>
</FilesMatch>
# CORS
#<IfModule mod_headers.c>
# Header set Access-Control-Allow-Origin "*"
#</IfModule>
# ------------------------------------------------------------------------------
# | Cache + |
# ------------------------------------------------------------------------------
# CACHE + ETags
<FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf|ogv|mp4|webm|svg|ttf|woff|woff2|eot|js|css|pdf|txt|webp|webmanifest)$">
<IfModule mod_headers.c>
Header unset Set-Cookie
Header set Cache-Control "max-age=21772800"
header set vary "Accept-Encoding"
header append vary "User-Agent"
header append Cache-Control "public"
header append Keep-Alive "timeout=5, max=100"
header append Connection "Keep-Alive"
FileETag None
</IfModule>
</FilesMatch>
# 10 minutes = HTML, XML (RSS)
<FilesMatch "\.(html|htm|xml)$">
<IfModule mod_headers.c>
Header set Cache-Control "max-age=600"
header set vary "Accept-Encoding"
header append vary "User-Agent"
header append Cache-Control "private"
FileETag None
</IfModule>
</FilesMatch>
# DONT CACHE = NO CACHE FOR PHP
<FilesMatch "\.(pl|php|cgi|spl)$">
<IfModule mod_headers.c>
Header unset Cache-Control
Header unset Expires
Header unset Last-Modified
Header unset Pragma
#BrowserMatch "MSIE" force-no-vary
FileETag None
header set vary "Accept-Encoding"
header append vary "User-Agent"
header append Cache-Control "private"
#Header set X-UA-Compatible "IE=edge"
</IfModule>
</FilesMatch>
# ------------------------------------------------------------------------------
# | Redirects |
# ------------------------------------------------------------------------------
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# permanent
# RedirectPermanent /old-page.php http://www.mysite.com/new-page.php
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# temporary
# RedirectTemp /old-page.php http://www.mysite.com/new-page.php
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# other examples
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# URL with querystring to new one keeping the querystring (301 = permanent)
# RewriteCond %{QUERY_STRING} id=(\w+)
# RewriteRule ^old_path/index\.php http://www.new_site.com/new_path/index.php?id=%1 [L,R=301]
# URL to a hash fragment /some-path/whatever/ => /some-path/#whatever
# RewriteRule ^/some-path/(.*)/?$ /some-path/#$1 [R=301,L,NE]
# Rewrite short URL noooo to a file
# RewriteRule ^noooo$ /images/nooo.gif [L]