AddType text/x-component .htc
Options +FollowSymLinks -indexes
RewriteEngine on

# Force www throughout site.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# http redirect to main website
#RewriteCond %{HTTP_HOST} !^www\.maindomain\.com [NC]
#RewriteCond %{HTTP_HOST} !^.*\.mtcdevserver\.com [NC]
#RewriteRule ^(.*)$ http://www.maindomain.com/$1 [L,R=301]

# https redirect to main website
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} !.mtcdevserver[0-9]*
#RewriteRule ^ https://www.maindomain.co.uk%{REQUEST_URI} [L,R=301,QSA]

RewriteCond %{REQUEST_URI} !^/core/generator
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]


# Folder redirects
RewriteRule ^generator/?(.*) /core/generator/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^sitemap/?$ /core/sitemap/ [QSA,L]

# ABS rules (you may add this right before the CMS rules)
RewriteRule ^abs/resource/([0-9]+)/([0-9a-z\-]+)\/?$ /abs/resource.php?id_param=$1 [QSA,L]

# Vendor fonts - override fonts loaded by JS not having public prefix due to mix complilation not matching public path root
RewriteRule ^fonts/vendor(.*) /public/fonts/vendor/$1 [L]
RewriteRule ^vendor/telescope/(.*) /public/vendor/telescope/$1 [L]

# CMS Rules
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

# Error Handling
# Because core is multi-site system - one 404.html won't do the trick
# cms router shall handle and pull in the correct 404.html (still static)
ErrorDocument 404 /e404
ErrorDocument 403 /e404

#don't give access unless its for debugbar and on devserver
RewriteCond %{HTTP_HOST} !^.*\.mtcdevserver\.com [NC]
RewriteCond %{REQUEST_URI} !^.*debugbar.*$
RewriteRule ^vendor - [F]
RewriteRule ^.env - [F]

# Hide Configuration
RewriteRule ^storage - [F]
RewriteRule ^src - [F]
RewriteRule ^composer\.json - [F]
RewriteRule ^composer\.lock - [F]
RewriteRule ^\.gitignore - [F]
RewriteRule ^phpunit\.xml - [F]
RewriteRule ^README\.md - [F]
RewriteRule ^gulpfile\.js - [F]
RewriteRule ^package\.json - [F]

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access plus 0 seconds"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

# Compress these file types on server before sending to client
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE image/jpg
AddOutputFilterByType DEFLATE image/jpeg
AddOutputFilterByType DEFLATE image/gif
AddOutputFilterByType DEFLATE image/png

# Compress SVG
AddType image/svg+xml .svg
AddOutputFilterByType DEFLATE image/svg+xml

# Image Redirects for staging.

# If image does not exist on staging, fetch from live
# RewriteCond %{HTTP_HOST} !amplifiedclothing\.com [OR]
# RewriteCond %{HTTP_HOST} gld\.mtcdevserver\.com
# RewriteCond %{REQUEST_URI} \.(jpg|jpeg|gif|png|svg)$ [NC]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule (.*)$ https://www.amplifiedclothing.com/$1 [L]

# Image Redirects for forks.

# if on fork and image does not exist, fetch from staging
# RewriteCond %{HTTP_HOST} !amplifiedclothing\.com [OR]
# RewriteCond %{HTTP_HOST} !gld\.mtcdevserver\.com
# RewriteCond %{REQUEST_URI} \.(jpg|jpeg|gif|png|svg)$ [NC]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule (.*)$ https://www.gld.mtcdevserver.com/$1 [L]
