RewriteEngine On

Options -Indexes
ErrorDocument 404 /http404

AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm

Header unset X-Powered-By
Header set Vary: Accept-Encoding
Header set X-Frame-Options: SAMEORIGIN
Header set X-XSS-Protection: 1
Header set X-Content-Type-Options: nosniff
Header always edit Set-Cookie (.*) "$1; SameSite=Strict"

<ifmodule mod_xsendfile.c>
	XSendFile on
	SetEnv MOD_XSENDFILE_ENABLED 1
</ifmodule>

<ifmodule mod_deflate.c>
	AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/x-javascript application/json text/javascript
</ifmodule>

# 7 days
<FilesMatch "\.(?i:jpg|png|gif|jpeg|pdf|ico|icon)$">
	Header set Cache-Control "max-age=290304000, public"
	FileETag MTime Size
</FilesMatch>
<FilesMatch "\.(?i:html|htm|js|css|txt|xml)$">
	Header set Cache-Control "max-age=290304000, must-revalidate"
	AddDefaultCharset UTF-8
</FilesMatch>

# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)				[NC]
RewriteRule ^(.*)$ %{REQUEST_SCHEME}://%1/$1	[R=301,L]

# Optimize images & serve retina images if necessary.
RewriteRule \.(jpe?g|png|gif|webp)$ /retinaimages.php [NC,L]

# Remove index or index.php from URL if that's all we have.
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index(\.php)?$ /? [NC,L,R=301]

# Deny access to CHANGELOG.md
<IfModule authz_core_module>
	<Files "CHANGELOG.md">
		Require all denied
	</Files>
</IfModule>
<IfModule !authz_core_module>
	<Files "CHANGELOG.md">
		Deny from all
	</Files>
</IfModule>

# Translate page requested.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
