# ------------------------------------------------------------------------------
# | CORS-enabled images                                                        |
# ------------------------------------------------------------------------------
<IfModule mod_setenvif.c>
	<IfModule mod_headers.c>
		<FilesMatch "\.(gif|ico|jpe?g|png|svgz?|webp)$">
			SetEnvIf Origin ":" IS_CORS
			Header set Access-Control-Allow-Origin "*" env=IS_CORS
		</FilesMatch>
	</IfModule>
</IfModule>


# ------------------------------------------------------------------------------
# | Web fonts access                                                           |
# ------------------------------------------------------------------------------
<IfModule mod_headers.c>
	<FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff)$">
		Header set Access-Control-Allow-Origin "*"
	</FilesMatch>
</IfModule>


# ------------------------------------------------------------------------------
# | 404 error prevention for non-existing redirected folders                   |
# ------------------------------------------------------------------------------
Options -MultiViews


# ------------------------------------------------------------------------------
# | Force IE to render pages in the highest available mode in the various      |
# ------------------------------------------------------------------------------
<IfModule mod_headers.c>
	Header set X-UA-Compatible "IE=edge"
	<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|woff|xml|xpi)$">
		Header unset X-UA-Compatible
	</FilesMatch>
</IfModule>


# ------------------------------------------------------------------------------
# | Proper MIME types for all files                                            |
# ------------------------------------------------------------------------------
<IfModule mod_mime.c>

	AddType audio/mp4                                   m4a f4a f4b
	AddType audio/ogg                                   oga ogg

	AddType application/javascript                      js
	AddType application/json                            json

	AddType video/mp4                                   mp4 m4v f4v f4p
	AddType video/ogg                                   ogv
	AddType video/webm                                  webm
	AddType video/x-flv                                 flv

	AddType application/font-woff                       woff
	AddType application/vnd.ms-fontobject               eot

	AddType application/x-font-ttf                      ttc ttf
	AddType font/opentype                               otf

	AddType     image/svg+xml                           svg svgz
	AddEncoding gzip                                    svgz

	AddType application/octet-stream                    safariextz
	AddType application/x-chrome-extension              crx
	AddType application/x-opera-extension               oex
	AddType application/x-shockwave-flash               swf
	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                                ico
	AddType text/cache-manifest                         appcache manifest
	AddType text/vtt                                    vtt
	AddType text/x-component                            htc
	AddType text/x-vcard                                vcf

</IfModule>


# ------------------------------------------------------------------------------
# | UTF-8 encoding                                                             |
# ------------------------------------------------------------------------------
AddDefaultCharset utf-8
<IfModule mod_mime.c>
	AddCharset utf-8 .atom .css .js .json .rss .vtt .webapp .xml
</IfModule>


# ------------------------------------------------------------------------------
# | Rewrite engine                                                             |
# ------------------------------------------------------------------------------
<IfModule mod_rewrite.c>

	# Enable URL rewriting
	RewriteEngine On

	# Rules to set ApplicationContext based on hostname
	#RewriteCond %{HTTP_HOST} ^dev\.example\.com$
	#RewriteRule .? - [E=TYPO3_CONTEXT:Development]
	#RewriteCond %{HTTP_HOST} ^staging\.example\.com$
	#RewriteRule .? - [E=TYPO3_CONTEXT:Production/Staging]
	#RewriteCond %{HTTP_HOST} ^www\.example\.com$
	#RewriteRule .? - [E=TYPO3_CONTEXT:Production]

	# Using mod_rewrite in .htaccess files without knowing the RewriteBase
	# http://www.zeilenwechsel.de/it/articles/8/Using-mod_rewrite-in-.htaccess-files-without-knowing-the-RewriteBase.html
	RewriteBase /

	# Store the current location in an environment variable CWD
	RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
	RewriteRule ^.*$ - [E=CWD:%2]

	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]
	RewriteRule ^fileadmin/(.*/)?_recycler_/ - [F]
	RewriteRule ^fileadmin/templates/.*(\.txt|\.ts)$ - [F]
	RewriteRule ^typo3conf/ext/[^/]+/Configuration/ - [F]
	RewriteRule ^typo3conf/ext/[^/]+/Resources/Private/ - [F]
	RewriteRule ^(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]

	# Just by prefixing the environment variable, we can safely rewrite anything now
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{REQUEST_FILENAME} !-l
	RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]

</IfModule>


# ------------------------------------------------------------------------------
# | Block access to directories without a default document.                    |
# ------------------------------------------------------------------------------
<IfModule mod_autoindex.c>
	Options -Indexes
</IfModule>


# ------------------------------------------------------------------------------
# | Block access to hidden files and directories.                              |
# ------------------------------------------------------------------------------
<IfModule mod_rewrite.c>
	RewriteCond %{SCRIPT_FILENAME} -d [OR]
	RewriteCond %{SCRIPT_FILENAME} -f
	RewriteRule "(^|/)\." - [F]
</IfModule>


# ------------------------------------------------------------------------------
# | lock access to backup and source files.                                    |
# ------------------------------------------------------------------------------
<FilesMatch "(^#.*#|\.(bak|.ts|config|dist|fla|inc|ini|log|psd|sh|sql|sw[op])|~)$">
	Order allow,deny
	Deny from all
	Satisfy All
</FilesMatch>


# ------------------------------------------------------------------------------
# | Compression                                                                |
# ------------------------------------------------------------------------------
<IfModule mod_deflate.c>
	<IfModule mod_setenvif.c>
		<IfModule mod_headers.c>
			SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
			RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
		</IfModule>
	</IfModule>
	<IfModule mod_filter.c>
		AddOutputFilterByType DEFLATE application/atom+xml \
									  application/javascript \
									  application/json \
									  application/rss+xml \
									  application/vnd.ms-fontobject \
									  application/x-font-ttf \
									  application/x-web-app-manifest+json \
									  application/xhtml+xml \
									  application/xml \
									  font/opentype \
									  image/svg+xml \
									  image/x-icon \
									  text/css \
									  text/html \
									  text/plain \
									  text/x-component \
									  text/xml
	</IfModule>
</IfModule>


# ------------------------------------------------------------------------------
# | ETag removal                                                               |
# ------------------------------------------------------------------------------
<IfModule mod_headers.c>
	Header unset ETag
</IfModule>
FileETag None


# ------------------------------------------------------------------------------
# | Expires headers (for better cache control)                                 |
# ------------------------------------------------------------------------------
<IfModule mod_expires.c>

	ExpiresActive on
	ExpiresDefault                                      "access plus 1 month"

	ExpiresByType text/css                              "access plus 1 year"

	ExpiresByType application/json                      "access plus 0 seconds"
	ExpiresByType application/xml                       "access plus 0 seconds"
	ExpiresByType text/xml                              "access plus 0 seconds"

	ExpiresByType image/x-icon                          "access plus 1 week"

	ExpiresByType text/x-component                      "access plus 1 month"

	ExpiresByType text/html                             "access plus 0 seconds"

	ExpiresByType application/javascript                "access plus 1 year"

	ExpiresByType application/x-web-app-manifest+json   "access plus 0 seconds"
	ExpiresByType text/cache-manifest                   "access plus 0 seconds"

	ExpiresByType audio/ogg                             "access plus 1 month"
	ExpiresByType image/gif                             "access plus 1 month"
	ExpiresByType image/jpeg                            "access plus 1 month"
	ExpiresByType image/png                             "access plus 1 month"
	ExpiresByType video/mp4                             "access plus 1 month"
	ExpiresByType video/ogg                             "access plus 1 month"
	ExpiresByType video/webm                            "access plus 1 month"

	ExpiresByType application/atom+xml                  "access plus 1 hour"
	ExpiresByType application/rss+xml                   "access plus 1 hour"

	ExpiresByType application/font-woff                 "access plus 1 month"
	ExpiresByType application/vnd.ms-fontobject         "access plus 1 month"
	ExpiresByType application/x-font-ttf                "access plus 1 month"
	ExpiresByType font/opentype                         "access plus 1 month"
	ExpiresByType image/svg+xml                         "access plus 1 month"

</IfModule>