#Fix Rewrite
Options -Multiviews

RewriteEngine on

# enable symbolic links
Options +FollowSymLinks

# increase performance by disabling AllowOverride
# this htacces will be the default across the server
#AllowOverride None

# Disable directory browsing
Options All -Indexes

# Set the directory index
DirectoryIndex index.php

# Redirect Specific Files
RewriteRule ^favicon.ico Public/StatsCoach/img/icons/favicon.png [L]

# Remove www.
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]



# Turn on https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#prevent hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https://Stats.Coach/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]

# protect against DOS attacks by limiting file upload size [bytes]
LimitRequestBody 10240000

# Enable compression
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

# This scares me man
<IfModule mod_speling.c>
	CheckSpelling On
</IfModule>

# set the default language
DefaultLanguage en-US

# pass the default character set
AddDefaultCharset utf-8

# Error Redirects
ErrorDocument 404 https://stats.coach/404/

# Version Control for Dependancies
RewriteRule ^(.*)\.[\d]{10}\.(css|js|html)$ $1.$2 [L]

# Redirect anyhting thats not of the following file types to the index
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.icon|\.js|\.css|\.woff|.\woff2|\.map|\.mst)$
RewriteRule (.*) index.php [QSA]
</IfModule>

# Everything to the index
RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d   -- We dont want to redirect into direcotries
RewriteRule ^(.*)$ /index.php [NC,L,QSA]

# God forbit an uncaught error - Display contact method
#ServerSignature EMail
#SetEnv SERVER_ADMIN RicardMiles@stats.coach

# 1 YEAR - 29030400; 1 WEEK - 604800; 2 DAYS - 172800; 1 MIN  - 60

<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>

<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

<FilesMatch "\.(xml|txt|css|js|mst)$">
Header set Cache-Control "max-age=604800, proxy-revalidate"
</FilesMatch>

# TODO - Eventually we should cache mustache files
# normally 60
<FilesMatch "\.(html|htm|php)$">
Header set Cache-Control "max-age=0, private, proxy-revalidate"
</FilesMatch>

# deny access to evil robots site rippers offline browsers and other nasty scum
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^Anarchie [OR]
RewriteCond %{HTTP_USER_AGENT} ^ASPSeek [OR]
RewriteCond %{HTTP_USER_AGENT} ^attach [OR]
RewriteCond %{HTTP_USER_AGENT} ^autoemailspider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xenu [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus.*Webster [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.*$ http://www.google.com [R,L]
# send em to a hellish website of your choice
