#Fix Rewrite
# CarbonPHP doesnt require this file
# If you are building on apache place this file in the root directory.
# It's Caching will speed up your server. Read the comments to see if
# editing is required for your build (most likely)...

Options -Multiviews         #

RewriteEngine on            # For pre interprating urls in this file

# enable symbolic links
Options +FollowSymLinks     # aliases,

# If you experence errors when you first move this file its likely that you do not have
# HTTP2 installed/enabled on your computer, so comment out # the next three lines.
LoadModule http2_module modules/mod_http2.so
ProtocolsHonorOrder On
Protocols h2 http/1.1


# increase performance by disabling AllowOverride
# this htacces will be the default across the server
# This broke my server personally, but it would be
# excelent to have enabled if you can
AllowOverride None

# Disable directory browsing - This is fine, leave it
Options All -Indexes

# Set the directory index   - also fine..
DirectoryIndex index.php

# Redirect Specific Files   TODO - change
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 ( Cent OS )
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Turn on https ( Mac OS )
# RewriteCond %{HTTP:X-Forwarded-Proto} !https
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#prevent hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://example.com/.*$ [NC]    # Change This!!!
RewriteRule \.(png|gif|jpg)$ - [F]                           # File types to prevent other websites from serving


# 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>


# Ummmm sure
<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
