.htaccess 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. #####
  2. #
  3. # Example .htaccess file for TYPO3 CMS - for use with Apache Webserver
  4. #
  5. # This file includes settings for the following configuration options:
  6. #
  7. # - Compression
  8. # - Caching
  9. # - MIME types
  10. # - Cross Origin requests
  11. # - Rewriting and Access
  12. # - Miscellaneous
  13. # - PHP optimisation
  14. #
  15. # If you want to use it, you have to copy it to the root folder of your TYPO3 installation (if its
  16. # not there already) and rename it to '.htaccess'. To make .htaccess files work, you might need to
  17. # adjust the 'AllowOverride' directive in your Apache configuration file.
  18. #
  19. # IMPORTANT: You may need to change this file depending on your TYPO3 installation!
  20. # Consider adding this file's content to your webserver's configuration directly for speed improvement
  21. #
  22. # Lots of the options are taken from https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess
  23. #
  24. ####
  25. SetEnv TYPO3_CONTEXT Development
  26. SetEnv TYPO3_OPTIMIZE 1
  27. ### Begin: Compression ###
  28. # Compressing resource files will save bandwidth and so improve loading speed especially for users
  29. # with slower internet connections. TYPO3 can compress the .js and .css files for you.
  30. # *) Uncomment the following lines and
  31. # *) Set $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'] = 9 for the Backend
  32. # *) Set $GLOBALS['TYPO3_CONF_VARS']['FE']['compressionLevel'] = 9 together with the TypoScript properties
  33. # config.compressJs and config.compressCss for GZIP compression of Frontend JS and CSS files.
  34. <FilesMatch "\.js\.gzip$">
  35. AddType "text/javascript" .gzip
  36. </FilesMatch>
  37. <FilesMatch "\.css\.gzip$">
  38. AddType "text/css" .gzip
  39. </FilesMatch>
  40. AddEncoding gzip .gzip
  41. <IfModule mod_deflate.c>
  42. # Force compression for mangled `Accept-Encoding` request headers
  43. <IfModule mod_setenvif.c>
  44. <IfModule mod_headers.c>
  45. SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
  46. RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
  47. </IfModule>
  48. </IfModule>
  49. # Compress all output labeled with one of the following media types.
  50. #
  51. # (!) For Apache versions below version 2.3.7 you don't need to
  52. # enable `mod_filter` and can remove the `<IfModule mod_filter.c>`
  53. # and `</IfModule>` lines as `AddOutputFilterByType` is still in
  54. # the core directives.
  55. #
  56. # https://httpd.apache.org/docs/current/mod/mod_filter.html#addoutputfilterbytype
  57. <IfModule mod_filter.c>
  58. AddOutputFilterByType DEFLATE application/atom+xml \
  59. application/javascript \
  60. application/json \
  61. application/ld+json \
  62. application/manifest+json \
  63. application/rdf+xml \
  64. application/rss+xml \
  65. application/schema+json \
  66. application/vnd.geo+json \
  67. application/vnd.ms-fontobject \
  68. application/x-font-ttf \
  69. application/x-javascript \
  70. application/x-web-app-manifest+json \
  71. application/xhtml+xml \
  72. application/xml \
  73. font/eot \
  74. font/opentype \
  75. image/bmp \
  76. image/svg+xml \
  77. image/vnd.microsoft.icon \
  78. image/x-icon \
  79. text/cache-manifest \
  80. text/css \
  81. text/html \
  82. text/javascript \
  83. text/plain \
  84. text/vcard \
  85. text/vnd.rim.location.xloc \
  86. text/vtt \
  87. text/x-component \
  88. text/x-cross-domain-policy \
  89. text/xml
  90. </IfModule>
  91. <IfModule mod_mime.c>
  92. AddEncoding gzip svgz
  93. </IfModule>
  94. </IfModule>
  95. ### End: Compression ###
  96. ### Begin: Browser caching of resource files ###
  97. # This affects Frontend and Backend and increases performance.
  98. <IfModule mod_expires.c>
  99. ExpiresActive on
  100. ExpiresDefault "access plus 1 month"
  101. ExpiresByType text/css "access plus 1 year"
  102. ExpiresByType application/json "access plus 0 seconds"
  103. ExpiresByType application/ld+json "access plus 0 seconds"
  104. ExpiresByType application/schema+json "access plus 0 seconds"
  105. ExpiresByType application/vnd.geo+json "access plus 0 seconds"
  106. ExpiresByType application/xml "access plus 0 seconds"
  107. ExpiresByType text/xml "access plus 0 seconds"
  108. ExpiresByType image/vnd.microsoft.icon "access plus 1 week"
  109. ExpiresByType image/x-icon "access plus 1 week"
  110. ExpiresByType text/x-component "access plus 1 month"
  111. ExpiresByType text/html "access plus 0 seconds"
  112. ExpiresByType application/javascript "access plus 1 year"
  113. ExpiresByType application/x-javascript "access plus 1 year"
  114. ExpiresByType text/javascript "access plus 1 year"
  115. ExpiresByType application/manifest+json "access plus 1 week"
  116. ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
  117. ExpiresByType text/cache-manifest "access plus 0 seconds"
  118. ExpiresByType audio/ogg "access plus 1 month"
  119. ExpiresByType image/bmp "access plus 1 month"
  120. ExpiresByType image/gif "access plus 1 month"
  121. ExpiresByType image/jpeg "access plus 1 month"
  122. ExpiresByType image/png "access plus 1 month"
  123. ExpiresByType image/svg+xml "access plus 1 month"
  124. ExpiresByType image/webp "access plus 1 month"
  125. ExpiresByType video/mp4 "access plus 1 month"
  126. ExpiresByType video/ogg "access plus 1 month"
  127. ExpiresByType video/webm "access plus 1 month"
  128. ExpiresByType application/atom+xml "access plus 1 hour"
  129. ExpiresByType application/rdf+xml "access plus 1 hour"
  130. ExpiresByType application/rss+xml "access plus 1 hour"
  131. ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
  132. ExpiresByType font/eot "access plus 1 month"
  133. ExpiresByType font/opentype "access plus 1 month"
  134. ExpiresByType application/x-font-ttf "access plus 1 month"
  135. ExpiresByType application/font-woff "access plus 1 month"
  136. ExpiresByType application/x-font-woff "access plus 1 month"
  137. ExpiresByType font/woff "access plus 1 month"
  138. ExpiresByType application/font-woff2 "access plus 1 month"
  139. ExpiresByType text/x-cross-domain-policy "access plus 1 week"
  140. </IfModule>
  141. ### End: Browser caching of resource files ###
  142. ### Begin: MIME types ###
  143. # Proper MIME types for all files
  144. <IfModule mod_mime.c>
  145. # Data interchange
  146. AddType application/atom+xml atom
  147. AddType application/json json map topojson
  148. AddType application/ld+json jsonld
  149. AddType application/rss+xml rss
  150. AddType application/vnd.geo+json geojson
  151. AddType application/xml rdf xml
  152. # JavaScript
  153. AddType application/javascript js
  154. # Manifest files
  155. AddType application/manifest+json webmanifest
  156. AddType application/x-web-app-manifest+json webapp
  157. AddType text/cache-manifest appcache
  158. # Media files
  159. AddType audio/mp4 f4a f4b m4a
  160. AddType audio/ogg oga ogg opus
  161. AddType image/bmp bmp
  162. AddType image/svg+xml svg svgz
  163. AddType image/webp webp
  164. AddType video/mp4 f4v f4p m4v mp4
  165. AddType video/ogg ogv
  166. AddType video/webm webm
  167. AddType video/x-flv flv
  168. AddType image/x-icon cur ico
  169. # Web fonts
  170. AddType application/font-woff woff
  171. AddType application/font-woff2 woff2
  172. AddType application/vnd.ms-fontobject eot
  173. AddType application/x-font-ttf ttc ttf
  174. AddType font/opentype otf
  175. # Other
  176. AddType application/octet-stream safariextz
  177. AddType application/x-bb-appworld bbaw
  178. AddType application/x-chrome-extension crx
  179. AddType application/x-opera-extension oex
  180. AddType application/x-xpinstall xpi
  181. AddType text/vcard vcard vcf
  182. AddType text/vnd.rim.location.xloc xloc
  183. AddType text/vtt vtt
  184. AddType text/x-component htc
  185. </IfModule>
  186. # UTF-8 encoding
  187. AddDefaultCharset utf-8
  188. <IfModule mod_mime.c>
  189. AddCharset utf-8 .atom .css .js .json .manifest .rdf .rss .vtt .webapp .webmanifest .xml
  190. </IfModule>
  191. ### End: MIME types ###
  192. ### Begin: Cross Origin ###
  193. # Send the CORS header for images when browsers request it.
  194. <IfModule mod_setenvif.c>
  195. <IfModule mod_headers.c>
  196. <FilesMatch "\.(bmp|cur|gif|ico|jpe?g|png|svgz?|webp)$">
  197. SetEnvIf Origin ":" IS_CORS
  198. Header set Access-Control-Allow-Origin "*" env=IS_CORS
  199. </FilesMatch>
  200. </IfModule>
  201. </IfModule>
  202. # Allow cross-origin access to web fonts.
  203. <IfModule mod_headers.c>
  204. <FilesMatch "\.(eot|otf|tt[cf]|woff2?)$">
  205. Header set Access-Control-Allow-Origin "*"
  206. </FilesMatch>
  207. </IfModule>
  208. ### End: Cross Origin ###
  209. ### Begin: Rewriting and Access ###
  210. # You need rewriting, if you use a URL-Rewriting extension (RealURL, CoolUri).
  211. <IfModule mod_rewrite.c>
  212. # Enable URL rewriting
  213. RewriteEngine On
  214. # Store the current location in an environment variable CWD to use
  215. # mod_rewrite in .htaccess files without knowing the RewriteBase
  216. RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
  217. RewriteRule ^.*$ - [E=CWD:%2]
  218. # Rules to set ApplicationContext based on hostname
  219. #RewriteCond %{HTTP_HOST} ^dev\.example\.com$
  220. #RewriteRule .? - [E=TYPO3_CONTEXT:Development]
  221. #RewriteCond %{HTTP_HOST} ^staging\.example\.com$
  222. #RewriteRule .? - [E=TYPO3_CONTEXT:Production/Staging]
  223. #RewriteCond %{HTTP_HOST} ^www\.example\.com$
  224. #RewriteRule .? - [E=TYPO3_CONTEXT:Production]
  225. # Rule for versioned static files, configured through:
  226. # - $GLOBALS['TYPO3_CONF_VARS']['BE']['versionNumberInFilename']
  227. # - $GLOBALS['TYPO3_CONF_VARS']['FE']['versionNumberInFilename']
  228. # IMPORTANT: This rule has to be the very first RewriteCond in order to work!
  229. RewriteCond %{REQUEST_FILENAME} !-f
  230. RewriteCond %{REQUEST_FILENAME} !-d
  231. RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ %{ENV:CWD}$1.$3 [L]
  232. # Access block for folders
  233. RewriteRule _(?:recycler|temp)_/ - [F]
  234. RewriteRule fileadmin/templates/.*\.(?:txt|ts)$ - [F]
  235. RewriteRule ^(?:vendor|typo3_src|typo3temp/var) - [F]
  236. RewriteRule (?:typo3conf/ext|typo3/sysext|typo3/ext)/[^/]+/(?:Configuration|Resources/Private|Tests?|Documentation|docs?)/ - [F]
  237. # Block access to all hidden files and directories with the exception of
  238. # the visible content from within the `/.well-known/` hidden directory (RFC 5785).
  239. RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
  240. RewriteCond %{SCRIPT_FILENAME} -d [OR]
  241. RewriteCond %{SCRIPT_FILENAME} -f
  242. RewriteRule (?:^|/)\. - [F]
  243. # Stop rewrite processing, if we are in the typo3/ directory or any other known directory
  244. # NOTE: Add your additional local storages here
  245. RewriteRule ^(?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
  246. # If the file/symlink/directory does not exist => Redirect to index.php.
  247. # For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'.
  248. RewriteCond %{REQUEST_FILENAME} !-f
  249. RewriteCond %{REQUEST_FILENAME} !-d
  250. RewriteCond %{REQUEST_FILENAME} !-l
  251. RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]
  252. </IfModule>
  253. # Access block for files
  254. # Apache < 2.3
  255. <IfModule !mod_authz_core.c>
  256. <FilesMatch "(?i:^\.|^#.*#|^(?:ChangeLog|ToDo|Readme|License)(?:\.md|\.txt)?|^composer\.(?:json|lock)|^ext_conf_template\.txt|^ext_typoscript_constants\.txt|^ext_typoscript_setup\.txt|flexform[^.]*\.xml|locallang[^.]*\.(?:xml|xlf)|\.(?:bak|co?nf|cfg|ya?ml|ts|typoscript|tsconfig|dist|fla|in[ci]|log|sh|sql(?:\..*)?|sqlite(?:\..*)?|sw[op]|git.*|rc)|.*~)$">
  257. Order allow,deny
  258. Deny from all
  259. Satisfy All
  260. </FilesMatch>
  261. </IfModule>
  262. # Apache ≥ 2.3
  263. <IfModule mod_authz_core.c>
  264. <If "%{REQUEST_URI} =~ m#(?i:/\.|/\x23.*\x23|/(?:ChangeLog|ToDo|Readme|License)(?:\.md|\.txt)?|/composer\.(?:json|lock)|/ext_conf_template\.txt|/ext_typoscript_constants\.txt|/ext_typoscript_setup\.txt|flexform[^.]*\.xml|locallang[^.]*\.(?:xml|xlf)|\.(?:bak|co?nf|cfg|ya?ml|ts|typoscript|tsconfig|dist|fla|in[ci]|log|sh|sql(?:\..*)?|sqlite(?:\..*)?|sw[op]|git.*|rc)|.*~)$#">
  265. Require all denied
  266. </If>
  267. </IfModule>
  268. # Block access to vcs directories
  269. <IfModule mod_alias.c>
  270. RedirectMatch 404 /\.(?:git|svn|hg)/
  271. </IfModule>
  272. ### End: Rewriting and Access ###
  273. ### Begin: Miscellaneous ###
  274. # 404 error prevention for non-existing redirected folders
  275. Options -MultiViews
  276. # Make sure that directory listings are disabled.
  277. <IfModule mod_autoindex.c>
  278. Options -Indexes
  279. </IfModule>
  280. <IfModule mod_headers.c>
  281. # Force IE to render pages in the highest available mode
  282. Header set X-UA-Compatible "IE=edge"
  283. <FilesMatch "\.(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svgz?|ttf|vcf|webapp|webm|webp|woff2?|xml|xpi)$">
  284. Header unset X-UA-Compatible
  285. </FilesMatch>
  286. # Reducing MIME type security risks
  287. Header set X-Content-Type-Options "nosniff"
  288. </IfModule>
  289. # ETag removal
  290. <IfModule mod_headers.c>
  291. Header unset ETag
  292. </IfModule>
  293. FileETag None
  294. ### End: Miscellaneous ###
  295. # Add your own rules here.