.htaccess 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. # Apache Server Configs v2.14.0 | MIT License
  2. # https://github.com/h5bp/server-configs-apache
  3. # (!) Using `.htaccess` files slows down Apache, therefore, if you have
  4. # access to the main server configuration file (which is usually called
  5. # `httpd.conf`), you should add this logic there.
  6. #
  7. # https://httpd.apache.org/docs/current/howto/htaccess.html.
  8. # ######################################################################
  9. # # CROSS-ORIGIN #
  10. # ######################################################################
  11. # ----------------------------------------------------------------------
  12. # | Cross-origin requests |
  13. # ----------------------------------------------------------------------
  14. # Allow cross-origin requests.
  15. #
  16. # https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
  17. # http://enable-cors.org/
  18. # http://www.w3.org/TR/cors/
  19. # <IfModule mod_headers.c>
  20. # Header set Access-Control-Allow-Origin "*"
  21. # </IfModule>
  22. # ----------------------------------------------------------------------
  23. # | Cross-origin images |
  24. # ----------------------------------------------------------------------
  25. # Send the CORS header for images when browsers request it.
  26. #
  27. # https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image
  28. # https://blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html
  29. <IfModule mod_setenvif.c>
  30. <IfModule mod_headers.c>
  31. <FilesMatch "\.(bmp|cur|gif|ico|jpe?g|png|svgz?|webp)$">
  32. SetEnvIf Origin ":" IS_CORS
  33. Header set Access-Control-Allow-Origin "*" env=IS_CORS
  34. </FilesMatch>
  35. </IfModule>
  36. </IfModule>
  37. # ----------------------------------------------------------------------
  38. # | Cross-origin web fonts |
  39. # ----------------------------------------------------------------------
  40. # Allow cross-origin access to web fonts.
  41. <IfModule mod_headers.c>
  42. <FilesMatch "\.(eot|otf|tt[cf]|woff2?)$">
  43. Header set Access-Control-Allow-Origin "*"
  44. </FilesMatch>
  45. </IfModule>
  46. # ----------------------------------------------------------------------
  47. # | Cross-origin resource timing |
  48. # ----------------------------------------------------------------------
  49. # Allow cross-origin access to the timing information for all resources.
  50. #
  51. # If a resource isn't served with a `Timing-Allow-Origin` header that
  52. # would allow its timing information to be shared with the document,
  53. # some of the attributes of the `PerformanceResourceTiming` object will
  54. # be set to zero.
  55. #
  56. # http://www.w3.org/TR/resource-timing/
  57. # http://www.stevesouders.com/blog/2014/08/21/resource-timing-practical-tips/
  58. # <IfModule mod_headers.c>
  59. # Header set Timing-Allow-Origin: "*"
  60. # </IfModule>
  61. # ######################################################################
  62. # # ERRORS #
  63. # ######################################################################
  64. # ----------------------------------------------------------------------
  65. # | Custom error messages/pages |
  66. # ----------------------------------------------------------------------
  67. # Customize what Apache returns to the client in case of an error.
  68. # https://httpd.apache.org/docs/current/mod/core.html#errordocument
  69. ErrorDocument 404 /404.html
  70. # ----------------------------------------------------------------------
  71. # | Error prevention |
  72. # ----------------------------------------------------------------------
  73. # Disable the pattern matching based on filenames.
  74. #
  75. # This setting prevents Apache from returning a 404 error as the result
  76. # of a rewrite when the directory with the same name does not exist.
  77. #
  78. # https://httpd.apache.org/docs/current/content-negotiation.html#multiviews
  79. Options -MultiViews
  80. # ######################################################################
  81. # # INTERNET EXPLORER #
  82. # ######################################################################
  83. # ----------------------------------------------------------------------
  84. # | Document modes |
  85. # ----------------------------------------------------------------------
  86. # Force Internet Explorer 8/9/10 to render pages in the highest mode
  87. # available in the various cases when it may not.
  88. #
  89. # https://hsivonen.fi/doctype/#ie8
  90. #
  91. # (!) Starting with Internet Explorer 11, document modes are deprecated.
  92. # If your business still relies on older web apps and services that were
  93. # designed for older versions of Internet Explorer, you might want to
  94. # consider enabling `Enterprise Mode` throughout your company.
  95. #
  96. # https://msdn.microsoft.com/en-us/library/ie/bg182625.aspx#docmode
  97. # http://blogs.msdn.com/b/ie/archive/2014/04/02/stay-up-to-date-with-enterprise-mode-for-internet-explorer-11.aspx
  98. <IfModule mod_headers.c>
  99. Header set X-UA-Compatible "IE=edge"
  100. # `mod_headers` cannot match based on the content-type, however,
  101. # the `X-UA-Compatible` response header should be send only for
  102. # HTML documents and not for the other resources.
  103. <FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
  104. Header unset X-UA-Compatible
  105. </FilesMatch>
  106. </IfModule>
  107. # ----------------------------------------------------------------------
  108. # | Iframes cookies |
  109. # ----------------------------------------------------------------------
  110. # Allow cookies to be set from iframes in Internet Explorer.
  111. #
  112. # https://msdn.microsoft.com/en-us/library/ms537343.aspx
  113. # http://www.w3.org/TR/2000/CR-P3P-20001215/
  114. # <IfModule mod_headers.c>
  115. # Header set P3P "policyref=\"/w3c/p3p.xml\", CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\""
  116. # </IfModule>
  117. # ######################################################################
  118. # # MEDIA TYPES AND CHARACTER ENCODINGS #
  119. # ######################################################################
  120. # ----------------------------------------------------------------------
  121. # | Media types |
  122. # ----------------------------------------------------------------------
  123. # Serve resources with the proper media types (f.k.a. MIME types).
  124. #
  125. # https://www.iana.org/assignments/media-types/media-types.xhtml
  126. # https://httpd.apache.org/docs/current/mod/mod_mime.html#addtype
  127. <IfModule mod_mime.c>
  128. # Data interchange
  129. AddType application/atom+xml atom
  130. AddType application/json json map topojson
  131. AddType application/ld+json jsonld
  132. AddType application/rss+xml rss
  133. AddType application/vnd.geo+json geojson
  134. AddType application/xml rdf xml
  135. # JavaScript
  136. # Normalize to standard type.
  137. # https://tools.ietf.org/html/rfc4329#section-7.2
  138. AddType application/javascript js
  139. # Manifest files
  140. AddType application/manifest+json webmanifest
  141. AddType application/x-web-app-manifest+json webapp
  142. AddType text/cache-manifest appcache
  143. # Media files
  144. AddType audio/mp4 f4a f4b m4a
  145. AddType audio/ogg oga ogg opus
  146. AddType image/bmp bmp
  147. AddType image/svg+xml svg svgz
  148. AddType image/webp webp
  149. AddType video/mp4 f4v f4p m4v mp4
  150. AddType video/ogg ogv
  151. AddType video/webm webm
  152. AddType video/x-flv flv
  153. # Serving `.ico` image files with a different media type
  154. # prevents Internet Explorer from displaying then as images:
  155. # https://github.com/h5bp/html5-boilerplate/commit/37b5fec090d00f38de64b591bcddcb205aadf8ee
  156. AddType image/x-icon cur ico
  157. # Web fonts
  158. AddType application/font-woff woff
  159. AddType application/font-woff2 woff2
  160. AddType application/vnd.ms-fontobject eot
  161. # Browsers usually ignore the font media types and simply sniff
  162. # the bytes to figure out the font type.
  163. # https://mimesniff.spec.whatwg.org/#matching-a-font-type-pattern
  164. #
  165. # However, Blink and WebKit based browsers will show a warning
  166. # in the console if the following font types are served with any
  167. # other media types.
  168. AddType application/x-font-ttf ttc ttf
  169. AddType font/opentype otf
  170. # Other
  171. AddType application/octet-stream safariextz
  172. AddType application/x-bb-appworld bbaw
  173. AddType application/x-chrome-extension crx
  174. AddType application/x-opera-extension oex
  175. AddType application/x-xpinstall xpi
  176. AddType text/vcard vcard vcf
  177. AddType text/vnd.rim.location.xloc xloc
  178. AddType text/vtt vtt
  179. AddType text/x-component htc
  180. </IfModule>
  181. # ----------------------------------------------------------------------
  182. # | Character encodings |
  183. # ----------------------------------------------------------------------
  184. # Serve all resources labeled as `text/html` or `text/plain`
  185. # with the media type `charset` parameter set to `UTF-8`.
  186. #
  187. # https://httpd.apache.org/docs/current/mod/core.html#adddefaultcharset
  188. AddDefaultCharset utf-8
  189. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  190. # Serve the following file types with the media type `charset`
  191. # parameter set to `UTF-8`.
  192. #
  193. # https://httpd.apache.org/docs/current/mod/mod_mime.html#addcharset
  194. <IfModule mod_mime.c>
  195. AddCharset utf-8 .atom \
  196. .bbaw \
  197. .css \
  198. .geojson \
  199. .js \
  200. .json \
  201. .jsonld \
  202. .manifest \
  203. .rdf \
  204. .rss \
  205. .topojson \
  206. .vtt \
  207. .webapp \
  208. .webmanifest \
  209. .xloc \
  210. .xml
  211. </IfModule>
  212. # ######################################################################
  213. # # REWRITES #
  214. # ######################################################################
  215. # ----------------------------------------------------------------------
  216. # | Rewrite engine |
  217. # ----------------------------------------------------------------------
  218. # (1) Turn on the rewrite engine (this is necessary in order for
  219. # the `RewriteRule` directives to work).
  220. #
  221. # https://httpd.apache.org/docs/current/mod/mod_rewrite.html#RewriteEngine
  222. #
  223. # (2) Enable the `FollowSymLinks` option if it isn't already.
  224. #
  225. # https://httpd.apache.org/docs/current/mod/core.html#options
  226. #
  227. # (3) If your web host doesn't allow the `FollowSymlinks` option,
  228. # you need to comment it out or remove it, and then uncomment
  229. # the `Options +SymLinksIfOwnerMatch` line (4), but be aware
  230. # of the performance impact.
  231. #
  232. # https://httpd.apache.org/docs/current/misc/perf-tuning.html#symlinks
  233. #
  234. # (4) Some cloud hosting services will require you set `RewriteBase`.
  235. #
  236. # https://www.rackspace.com/knowledge_center/frequently-asked-question/why-is-modrewrite-not-working-on-my-site
  237. # https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
  238. #
  239. # (5) Depending on how your server is set up, you may also need to
  240. # use the `RewriteOptions` directive to enable some options for
  241. # the rewrite engine.
  242. #
  243. # https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteoptions
  244. #
  245. # (6) Set %{ENV:PROTO} variable, to allow rewrites to redirect with the
  246. # appropriate schema automatically (http or https).
  247. <IfModule mod_rewrite.c>
  248. # (1)
  249. RewriteEngine On
  250. # (2)
  251. Options +FollowSymlinks
  252. # (3)
  253. # Options +SymLinksIfOwnerMatch
  254. # (4)
  255. # RewriteBase /
  256. # (5)
  257. # RewriteOptions <options>
  258. # (6)
  259. RewriteCond %{HTTPS} =on
  260. RewriteRule ^ - [env=proto:https]
  261. RewriteCond %{HTTPS} !=on
  262. RewriteRule ^ - [env=proto:http]
  263. </IfModule>
  264. # ----------------------------------------------------------------------
  265. # | Forcing `https://` |
  266. # ----------------------------------------------------------------------
  267. # Redirect from the `http://` to the `https://` version of the URL.
  268. # https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
  269. # <IfModule mod_rewrite.c>
  270. # RewriteEngine On
  271. # RewriteCond %{HTTPS} !=on
  272. # RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
  273. # </IfModule>
  274. # ----------------------------------------------------------------------
  275. # | Suppressing / Forcing the `www.` at the beginning of URLs |
  276. # ----------------------------------------------------------------------
  277. # The same content should never be available under two different
  278. # URLs, especially not with and without `www.` at the beginning.
  279. # This can cause SEO problems (duplicate content), and therefore,
  280. # you should choose one of the alternatives and redirect the other
  281. # one.
  282. #
  283. # By default `Option 1` (no `www.`) is activated.
  284. # http://no-www.org/faq.php?q=class_b
  285. #
  286. # If you would prefer to use `Option 2`, just comment out all the
  287. # lines from `Option 1` and uncomment the ones from `Option 2`.
  288. #
  289. # (!) NEVER USE BOTH RULES AT THE SAME TIME!
  290. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  291. # Option 1: rewrite www.example.com → example.com
  292. <IfModule mod_rewrite.c>
  293. RewriteEngine On
  294. RewriteCond %{HTTPS} !=on
  295. RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  296. RewriteRule ^ %{ENV:PROTO}://%1%{REQUEST_URI} [R=301,L]
  297. </IfModule>
  298. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  299. # Option 2: rewrite example.com → www.example.com
  300. #
  301. # Be aware that the following might not be a good idea if you use "real"
  302. # subdomains for certain parts of your website.
  303. # <IfModule mod_rewrite.c>
  304. # RewriteEngine On
  305. # RewriteCond %{HTTPS} !=on
  306. # RewriteCond %{HTTP_HOST} !^www\. [NC]
  307. # RewriteCond %{SERVER_ADDR} !=127.0.0.1
  308. # RewriteCond %{SERVER_ADDR} !=::1
  309. # RewriteRule ^ %{ENV:PROTO}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  310. # </IfModule>
  311. # ######################################################################
  312. # # SECURITY #
  313. # ######################################################################
  314. # ----------------------------------------------------------------------
  315. # | Clickjacking |
  316. # ----------------------------------------------------------------------
  317. # Protect website against clickjacking.
  318. #
  319. # The example below sends the `X-Frame-Options` response header with
  320. # the value `DENY`, informing browsers not to display the content of
  321. # the web page in any frame.
  322. #
  323. # This might not be the best setting for everyone. You should read
  324. # about the other two possible values the `X-Frame-Options` header
  325. # field can have: `SAMEORIGIN` and `ALLOW-FROM`.
  326. # https://tools.ietf.org/html/rfc7034#section-2.1.
  327. #
  328. # Keep in mind that while you could send the `X-Frame-Options` header
  329. # for all of your website’s pages, this has the potential downside that
  330. # it forbids even non-malicious framing of your content (e.g.: when
  331. # users visit your website using a Google Image Search results page).
  332. #
  333. # Nonetheless, you should ensure that you send the `X-Frame-Options`
  334. # header for all pages that allow a user to make a state changing
  335. # operation (e.g: pages that contain one-click purchase links, checkout
  336. # or bank-transfer confirmation pages, pages that make permanent
  337. # configuration changes, etc.).
  338. #
  339. # Sending the `X-Frame-Options` header can also protect your website
  340. # against more than just clickjacking attacks:
  341. # https://cure53.de/xfo-clickjacking.pdf.
  342. #
  343. # https://tools.ietf.org/html/rfc7034
  344. # http://blogs.msdn.com/b/ieinternals/archive/2010/03/30/combating-clickjacking-with-x-frame-options.aspx
  345. # https://www.owasp.org/index.php/Clickjacking
  346. # <IfModule mod_headers.c>
  347. # Header set X-Frame-Options "DENY"
  348. # # `mod_headers` cannot match based on the content-type, however,
  349. # # the `X-Frame-Options` response header should be send only for
  350. # # HTML documents and not for the other resources.
  351. # <FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
  352. # Header unset X-Frame-Options
  353. # </FilesMatch>
  354. # </IfModule>
  355. # ----------------------------------------------------------------------
  356. # | Content Security Policy (CSP) |
  357. # ----------------------------------------------------------------------
  358. # Mitigate the risk of cross-site scripting and other content-injection
  359. # attacks.
  360. #
  361. # This can be done by setting a `Content Security Policy` which
  362. # whitelists trusted sources of content for your website.
  363. #
  364. # The example header below allows ONLY scripts that are loaded from
  365. # the current website's origin (no inline scripts, no CDN, etc).
  366. # That almost certainly won't work as-is for your website!
  367. #
  368. # To make things easier, you can use an online CSP header generator
  369. # such as: http://cspisawesome.com/.
  370. #
  371. # http://content-security-policy.com/
  372. # http://www.html5rocks.com/en/tutorials/security/content-security-policy/
  373. # http://www.w3.org/TR/CSP11/).
  374. # <IfModule mod_headers.c>
  375. # Header set Content-Security-Policy "script-src 'self'; object-src 'self'"
  376. # # `mod_headers` cannot match based on the content-type, however,
  377. # # the `Content-Security-Policy` response header should be send
  378. # # only for HTML documents and not for the other resources.
  379. # <FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
  380. # Header unset Content-Security-Policy
  381. # </FilesMatch>
  382. # </IfModule>
  383. # ----------------------------------------------------------------------
  384. # | File access |
  385. # ----------------------------------------------------------------------
  386. # Block access to directories without a default document.
  387. #
  388. # You should leave the following uncommented, as you shouldn't allow
  389. # anyone to surf through every directory on your server (which may
  390. # includes rather private places such as the CMS's directories).
  391. <IfModule mod_autoindex.c>
  392. Options -Indexes
  393. </IfModule>
  394. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  395. # Block access to all hidden files and directories with the exception of
  396. # the visible content from within the `/.well-known/` hidden directory.
  397. #
  398. # These types of files usually contain user preferences or the preserved
  399. # state of an utility, and can include rather private places like, for
  400. # example, the `.git` or `.svn` directories.
  401. #
  402. # The `/.well-known/` directory represents the standard (RFC 5785) path
  403. # prefix for "well-known locations" (e.g.: `/.well-known/manifest.json`,
  404. # `/.well-known/keybase.txt`), and therefore, access to its visible
  405. # content should not be blocked.
  406. #
  407. # https://www.mnot.net/blog/2010/04/07/well-known
  408. # https://tools.ietf.org/html/rfc5785
  409. <IfModule mod_rewrite.c>
  410. RewriteEngine On
  411. RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
  412. RewriteCond %{SCRIPT_FILENAME} -d [OR]
  413. RewriteCond %{SCRIPT_FILENAME} -f
  414. RewriteRule "(^|/)\." - [F]
  415. </IfModule>
  416. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  417. # Block access to files that can expose sensitive information.
  418. #
  419. # By default, block access to backup and source files that may be
  420. # left by some text editors and can pose a security risk when anyone
  421. # has access to them.
  422. #
  423. # http://feross.org/cmsploit/
  424. #
  425. # (!) Update the `<FilesMatch>` regular expression from below to
  426. # include any files that might end up on your production server and
  427. # can expose sensitive information about your website. These files may
  428. # include: configuration files, files that contain metadata about the
  429. # project (e.g.: project dependencies), build scripts, etc..
  430. <FilesMatch "(^#.*#|\.(bak|conf|dist|fla|in[ci]|log|psd|sh|sql|sw[op])|~)$">
  431. # Apache < 2.3
  432. <IfModule !mod_authz_core.c>
  433. Order allow,deny
  434. Deny from all
  435. Satisfy All
  436. </IfModule>
  437. # Apache ≥ 2.3
  438. <IfModule mod_authz_core.c>
  439. Require all denied
  440. </IfModule>
  441. </FilesMatch>
  442. # ----------------------------------------------------------------------
  443. # | HTTP Strict Transport Security (HSTS) |
  444. # ----------------------------------------------------------------------
  445. # Force client-side SSL redirection.
  446. #
  447. # If a user types `example.com` in their browser, even if the server
  448. # redirects them to the secure version of the website, that still leaves
  449. # a window of opportunity (the initial HTTP connection) for an attacker
  450. # to downgrade or redirect the request.
  451. #
  452. # The following header ensures that browser will ONLY connect to your
  453. # server via HTTPS, regardless of what the users type in the browser's
  454. # address bar.
  455. #
  456. # (!) Remove the `includeSubDomains` optional directive if the website's
  457. # subdomains are not using HTTPS.
  458. #
  459. # http://www.html5rocks.com/en/tutorials/security/transport-layer-security/
  460. # https://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec-14#section-6.1
  461. # http://blogs.msdn.com/b/ieinternals/archive/2014/08/18/hsts-strict-transport-security-attacks-mitigations-deployment-https.aspx
  462. # <IfModule mod_headers.c>
  463. # Header always set Strict-Transport-Security "max-age=16070400; includeSubDomains"
  464. # </IfModule>
  465. # ----------------------------------------------------------------------
  466. # | Reducing MIME type security risks |
  467. # ----------------------------------------------------------------------
  468. # Prevent some browsers from MIME-sniffing the response.
  469. #
  470. # This reduces exposure to drive-by download attacks and cross-origin
  471. # data leaks, and should be left uncommented, especially if the server
  472. # is serving user-uploaded content or content that could potentially be
  473. # treated as executable by the browser.
  474. #
  475. # http://www.slideshare.net/hasegawayosuke/owasp-hasegawa
  476. # http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
  477. # https://msdn.microsoft.com/en-us/library/ie/gg622941.aspx
  478. # https://mimesniff.spec.whatwg.org/
  479. <IfModule mod_headers.c>
  480. Header set X-Content-Type-Options "nosniff"
  481. </IfModule>
  482. # ----------------------------------------------------------------------
  483. # | Reflected Cross-Site Scripting (XSS) attacks |
  484. # ----------------------------------------------------------------------
  485. # (1) Try to re-enable the cross-site scripting (XSS) filter built
  486. # into most web browsers.
  487. #
  488. # The filter is usually enabled by default, but in some cases it
  489. # may be disabled by the user. However, in Internet Explorer for
  490. # example, it can be re-enabled just by sending the
  491. # `X-XSS-Protection` header with the value of `1`.
  492. #
  493. # (2) Prevent web browsers from rendering the web page if a potential
  494. # reflected (a.k.a non-persistent) XSS attack is detected by the
  495. # filter.
  496. #
  497. # By default, if the filter is enabled and browsers detect a
  498. # reflected XSS attack, they will attempt to block the attack
  499. # by making the smallest possible modifications to the returned
  500. # web page.
  501. #
  502. # Unfortunately, in some browsers (e.g.: Internet Explorer),
  503. # this default behavior may allow the XSS filter to be exploited,
  504. # thereby, it's better to inform browsers to prevent the rendering
  505. # of the page altogether, instead of attempting to modify it.
  506. #
  507. # https://hackademix.net/2009/11/21/ies-xss-filter-creates-xss-vulnerabilities
  508. #
  509. # (!) Do not rely on the XSS filter to prevent XSS attacks! Ensure that
  510. # you are taking all possible measures to prevent XSS attacks, the
  511. # most obvious being: validating and sanitizing your website's inputs.
  512. #
  513. # http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-iv-the-xss-filter.aspx
  514. # http://blogs.msdn.com/b/ieinternals/archive/2011/01/31/controlling-the-internet-explorer-xss-filter-with-the-x-xss-protection-http-header.aspx
  515. # https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29
  516. # <IfModule mod_headers.c>
  517. # # (1) (2)
  518. # Header set X-XSS-Protection "1; mode=block"
  519. # # `mod_headers` cannot match based on the content-type, however,
  520. # # the `X-XSS-Protection` response header should be send only for
  521. # # HTML documents and not for the other resources.
  522. # <FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
  523. # Header unset X-XSS-Protection
  524. # </FilesMatch>
  525. # </IfModule>
  526. # ----------------------------------------------------------------------
  527. # | Server-side technology information |
  528. # ----------------------------------------------------------------------
  529. # Remove the `X-Powered-By` response header that:
  530. #
  531. # * is set by some frameworks and server-side languages
  532. # (e.g.: ASP.NET, PHP), and its value contains information
  533. # about them (e.g.: their name, version number)
  534. #
  535. # * doesn't provide any value as far as users are concern,
  536. # and in some cases, the information provided by it can
  537. # be used by attackers
  538. #
  539. # (!) If you can, you should disable the `X-Powered-By` header from the
  540. # language / framework level (e.g.: for PHP, you can do that by setting
  541. # `expose_php = off` in `php.ini`)
  542. #
  543. # https://php.net/manual/en/ini.core.php#ini.expose-php
  544. <IfModule mod_headers.c>
  545. Header unset X-Powered-By
  546. </IfModule>
  547. # ----------------------------------------------------------------------
  548. # | Server software information |
  549. # ----------------------------------------------------------------------
  550. # Prevent Apache from adding a trailing footer line containing
  551. # information about the server to the server-generated documents
  552. # (e.g.: error messages, directory listings, etc.)
  553. #
  554. # https://httpd.apache.org/docs/current/mod/core.html#serversignature
  555. ServerSignature Off
  556. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  557. # Prevent Apache from sending in the `Server` response header its
  558. # exact version number, the description of the generic OS-type or
  559. # information about its compiled-in modules.
  560. #
  561. # (!) The `ServerTokens` directive will only work in the main server
  562. # configuration file, so don't try to enable it in the `.htaccess` file!
  563. #
  564. # https://httpd.apache.org/docs/current/mod/core.html#servertokens
  565. #ServerTokens Prod
  566. # ######################################################################
  567. # # WEB PERFORMANCE #
  568. # ######################################################################
  569. # ----------------------------------------------------------------------
  570. # | Compression |
  571. # ----------------------------------------------------------------------
  572. <IfModule mod_deflate.c>
  573. # Force compression for mangled `Accept-Encoding` request headers
  574. # https://developer.yahoo.com/blogs/ydn/pushing-beyond-gzipping-25601.html
  575. <IfModule mod_setenvif.c>
  576. <IfModule mod_headers.c>
  577. SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
  578. RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
  579. </IfModule>
  580. </IfModule>
  581. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  582. # Compress all output labeled with one of the following media types.
  583. #
  584. # (!) For Apache versions below version 2.3.7 you don't need to
  585. # enable `mod_filter` and can remove the `<IfModule mod_filter.c>`
  586. # and `</IfModule>` lines as `AddOutputFilterByType` is still in
  587. # the core directives.
  588. #
  589. # https://httpd.apache.org/docs/current/mod/mod_filter.html#addoutputfilterbytype
  590. <IfModule mod_filter.c>
  591. AddOutputFilterByType DEFLATE "application/atom+xml" \
  592. "application/javascript" \
  593. "application/json" \
  594. "application/ld+json" \
  595. "application/manifest+json" \
  596. "application/rdf+xml" \
  597. "application/rss+xml" \
  598. "application/schema+json" \
  599. "application/vnd.geo+json" \
  600. "application/vnd.ms-fontobject" \
  601. "application/x-font-ttf" \
  602. "application/x-javascript" \
  603. "application/x-web-app-manifest+json" \
  604. "application/xhtml+xml" \
  605. "application/xml" \
  606. "font/eot" \
  607. "font/opentype" \
  608. "image/bmp" \
  609. "image/svg+xml" \
  610. "image/vnd.microsoft.icon" \
  611. "image/x-icon" \
  612. "text/cache-manifest" \
  613. "text/css" \
  614. "text/html" \
  615. "text/javascript" \
  616. "text/plain" \
  617. "text/vcard" \
  618. "text/vnd.rim.location.xloc" \
  619. "text/vtt" \
  620. "text/x-component" \
  621. "text/x-cross-domain-policy" \
  622. "text/xml"
  623. </IfModule>
  624. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  625. # Map the following filename extensions to the specified
  626. # encoding type in order to make Apache serve the file types
  627. # with the appropriate `Content-Encoding` response header
  628. # (do note that this will NOT make Apache compress them!).
  629. #
  630. # If these files types would be served without an appropriate
  631. # `Content-Enable` response header, client applications (e.g.:
  632. # browsers) wouldn't know that they first need to uncompress
  633. # the response, and thus, wouldn't be able to understand the
  634. # content.
  635. #
  636. # https://httpd.apache.org/docs/current/mod/mod_mime.html#addencoding
  637. <IfModule mod_mime.c>
  638. AddEncoding gzip svgz
  639. </IfModule>
  640. </IfModule>
  641. # ----------------------------------------------------------------------
  642. # | Content transformation |
  643. # ----------------------------------------------------------------------
  644. # Prevent intermediate caches or proxies (e.g.: such as the ones
  645. # used by mobile network providers) from modifying the website's
  646. # content.
  647. #
  648. # https://tools.ietf.org/html/rfc2616#section-14.9.5
  649. #
  650. # (!) If you are using `mod_pagespeed`, please note that setting
  651. # the `Cache-Control: no-transform` response header will prevent
  652. # `PageSpeed` from rewriting `HTML` files, and, if the
  653. # `ModPagespeedDisableRewriteOnNoTransform` directive isn't set
  654. # to `off`, also from rewriting other resources.
  655. #
  656. # https://developers.google.com/speed/pagespeed/module/configuration#notransform
  657. # <IfModule mod_headers.c>
  658. # Header merge Cache-Control "no-transform"
  659. # </IfModule>
  660. # ----------------------------------------------------------------------
  661. # | ETags |
  662. # ----------------------------------------------------------------------
  663. # Remove `ETags` as resources are sent with far-future expires headers.
  664. #
  665. # https://developer.yahoo.com/performance/rules.html#etags
  666. # https://tools.ietf.org/html/rfc7232#section-2.3
  667. # `FileETag None` doesn't work in all cases.
  668. <IfModule mod_headers.c>
  669. Header unset ETag
  670. </IfModule>
  671. FileETag None
  672. # ----------------------------------------------------------------------
  673. # | Expires headers |
  674. # ----------------------------------------------------------------------
  675. # Serve resources with far-future expires headers.
  676. #
  677. # (!) If you don't control versioning with filename-based
  678. # cache busting, you should consider lowering the cache times
  679. # to something like one week.
  680. #
  681. # https://httpd.apache.org/docs/current/mod/mod_expires.html
  682. <IfModule mod_expires.c>
  683. ExpiresActive on
  684. ExpiresDefault "access plus 1 month"
  685. # CSS
  686. ExpiresByType text/css "access plus 1 year"
  687. # Data interchange
  688. ExpiresByType application/atom+xml "access plus 1 hour"
  689. ExpiresByType application/rdf+xml "access plus 1 hour"
  690. ExpiresByType application/rss+xml "access plus 1 hour"
  691. ExpiresByType application/json "access plus 0 seconds"
  692. ExpiresByType application/ld+json "access plus 0 seconds"
  693. ExpiresByType application/schema+json "access plus 0 seconds"
  694. ExpiresByType application/vnd.geo+json "access plus 0 seconds"
  695. ExpiresByType application/xml "access plus 0 seconds"
  696. ExpiresByType text/xml "access plus 0 seconds"
  697. # Favicon (cannot be renamed!) and cursor images
  698. ExpiresByType image/vnd.microsoft.icon "access plus 1 week"
  699. ExpiresByType image/x-icon "access plus 1 week"
  700. # HTML
  701. ExpiresByType text/html "access plus 0 seconds"
  702. # JavaScript
  703. ExpiresByType application/javascript "access plus 1 year"
  704. ExpiresByType application/x-javascript "access plus 1 year"
  705. ExpiresByType text/javascript "access plus 1 year"
  706. # Manifest files
  707. ExpiresByType application/manifest+json "access plus 1 week"
  708. ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
  709. ExpiresByType text/cache-manifest "access plus 0 seconds"
  710. # Media files
  711. ExpiresByType audio/ogg "access plus 1 month"
  712. ExpiresByType image/bmp "access plus 1 month"
  713. ExpiresByType image/gif "access plus 1 month"
  714. ExpiresByType image/jpeg "access plus 1 month"
  715. ExpiresByType image/png "access plus 1 month"
  716. ExpiresByType image/svg+xml "access plus 1 month"
  717. ExpiresByType image/webp "access plus 1 month"
  718. ExpiresByType video/mp4 "access plus 1 month"
  719. ExpiresByType video/ogg "access plus 1 month"
  720. ExpiresByType video/webm "access plus 1 month"
  721. # Web fonts
  722. # Embedded OpenType (EOT)
  723. ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
  724. ExpiresByType font/eot "access plus 1 month"
  725. # OpenType
  726. ExpiresByType font/opentype "access plus 1 month"
  727. # TrueType
  728. ExpiresByType application/x-font-ttf "access plus 1 month"
  729. # Web Open Font Format (WOFF) 1.0
  730. ExpiresByType application/font-woff "access plus 1 month"
  731. ExpiresByType application/x-font-woff "access plus 1 month"
  732. ExpiresByType font/woff "access plus 1 month"
  733. # Web Open Font Format (WOFF) 2.0
  734. ExpiresByType application/font-woff2 "access plus 1 month"
  735. # Other
  736. ExpiresByType text/x-cross-domain-policy "access plus 1 week"
  737. </IfModule>
  738. # ----------------------------------------------------------------------
  739. # | File concatenation |
  740. # ----------------------------------------------------------------------
  741. # Allow concatenation from within specific files.
  742. #
  743. # e.g.:
  744. #
  745. # If you have the following lines in a file called, for
  746. # example, `main.combined.js`:
  747. #
  748. # <!--#include file="js/jquery.js" -->
  749. # <!--#include file="js/jquery.timer.js" -->
  750. #
  751. # Apache will replace those lines with the content of the
  752. # specified files.
  753. # <IfModule mod_include.c>
  754. # <FilesMatch "\.combined\.js$">
  755. # Options +Includes
  756. # AddOutputFilterByType INCLUDES application/javascript \
  757. # application/x-javascript \
  758. # text/javascript
  759. # SetOutputFilter INCLUDES
  760. # </FilesMatch>
  761. # <FilesMatch "\.combined\.css$">
  762. # Options +Includes
  763. # AddOutputFilterByType INCLUDES text/css
  764. # SetOutputFilter INCLUDES
  765. # </FilesMatch>
  766. # </IfModule>
  767. # ----------------------------------------------------------------------
  768. # | Filename-based cache busting |
  769. # ----------------------------------------------------------------------
  770. # If you're not using a build process to manage your filename version
  771. # revving, you might want to consider enabling the following directives
  772. # to route all requests such as `/style.12345.css` to `/style.css`.
  773. #
  774. # To understand why this is important and even a better solution than
  775. # using something like `*.css?v231`, please see:
  776. # http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
  777. # <IfModule mod_rewrite.c>
  778. # RewriteEngine On
  779. # RewriteCond %{REQUEST_FILENAME} !-f
  780. # RewriteRule ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ $1.$3 [L]
  781. # </IfModule>