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

RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

# Vite dev mode: rewrite font paths that get base-prefixed by HMR CSS injection
RewriteCond %{HTTP_HOST} ^localhost$ [OR]
RewriteCond %{HTTP_HOST} \.mtcdevserver
RewriteRule ^public/build/sites/default/fonts/(.*)$ /sites/default/fonts/$1 [L]
RewriteRule ^public/build/sites/default/images/(.*)$ /sites/default/images/$1 [L]

Redirect 301 /robots.txt/ /robots.txt
Redirect 301 /sitemap.xml/ /sitemap.xml

RedirectMatch 301 ^/online-doctor(/)?$ /conditions/

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

# Proxy missing uploads to production (localhost only)
# RewriteCond %{HTTP_HOST} ^localhost$ [NC]
# RewriteCond %{REQUEST_URI} ^/uploads/
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule ^uploads/(.*)$ https://STAGING_DOMAIN/uploads/$1 [R=302,L]

# Fake image generator, great for quickly populating dummy images programmatically
RewriteRule fake_image(_([a-z]{1,20}))?(_([0-9]{1,2}))?\.png$ /core/images/image_faker.php?category=$2&picture_no=$4 [L]

RewriteRule ^newsletter(/)?$ /plugins/NewsletterSignup/ [QSA,L]

# Messaging
RewriteRule ^admin/messaging/?(.*) /plugins/MembersMessaging/admin/index.php?act=$1 [QSA,L]

# Judopay
RewriteRule ^shop\/checkout\/judopay\/?(.*)\/$ /plugins/Judopay/checkout/$1.php [QSA,L]

# RyftPay
RewriteRule ^shop/checkout/ryftpay/?(.*) /plugins/RyftPay/checkout/$1.php [QSA,L]

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

# Home
RewriteRule ^home(/)$ / [R=301,L]

# Browse Page
RewriteRule ^shop/$ /pharmacy/ [R=301,QSA,L]
RewriteRule ^shop/browse/$ /pharmacy/ [R=301,QSA,L]
RewriteRule ^browse/$ /pharmacy/ [R=301,QSA,L]
RewriteRule ^browse$ /pharmacy/ [R=301,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^browse/ajax.php(.*) /shop/browse/ajax.php [QSA]
RewriteRule ^pharmacy(.*) /shop/browse/index.php [QSA]

# Item page
RewriteRule ^item/([0-9]+)(/([_\&\'\,\+A-Za-z0-9-]+))?/([_\&\'\,\+A-Za-z0-9-]+).html$ shop/item.php?id=$1 [QSA]
RewriteRule ^medications/([a-zA-Z0-9\-]+)/?$ /shop/item.php?slug=$1 [QSA,L]

RewriteRule ^private_prescriptions(/)?(.*) /plugins/Prescriptions/$2 [QSA,L,NC]
RewriteRule ^members(/)?(.*) /modules/Members/$2 [QSA,L]

RewriteRule ^sitemap.xml /index.php [QSA,L]

# Categories landing
#RewriteRule ^online-doctor/([a-zA-Z\-]+)/([a-zA-Z0-9\-]+)(/?)$ /shop/item.php?slug=$2 [QSA,L]
#RewriteRule ^online-doctor/(.+)$ /shop/category.php?slug=$1 [QSA,L]

# CMS Rules
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(((([0-9a-z\-\\/]*)\/)|())([0-9a-z\-]+)\/?)$ /index.php [QSA,L,NC,E=FULLCMS_SLUG_URI:root/$1,E=FULLCMS_PAGE:$6]

# 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
# If the system has only one site you can use the cms auto generated 404.html
# which is located (depending on your site name) "/sites/www/404.html"
# ErrorDocument 404 /sites/www/404.html
# ErrorDocument 403 /sites/www/404.html

#debug-bar setting
RewriteRule ^debugbar/(.*) /vendor/maximebf/debugbar/src/DebugBar/Resources/$1 [L]

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

# Hide Configuration
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]
RewriteRule ^TODO\.rm - [F]

AddType application/font-woff woff
AddType application/font-woff2 woff2

AddType video/mp4 .mp4 .m4v

## 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 image/webp "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 year"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/font-woff "access 1 year"
ExpiresByType application/x-font-woff "access 1 year"
ExpiresByType font/woff "access 1 year"
ExpiresByType application/font-woff2 "access 1 year"
ExpiresByType image/svg+xml "access 1 year"
ExpiresByType video/mp4 "access plus 1 month"
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
AddOutputFilterByType DEFLATE image/webp

<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 rspheader ^Content-Encoding:.*gzip.*
</ifModule>
# Compress SVG
AddType image/svg+xml .svg
AddOutputFilterByType DEFLATE image/svg+xml

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php5_module>
   php_flag asp_tags Off
   php_flag display_errors Off
   php_value max_execution_time 600
   php_value max_input_time 60
   php_value max_input_vars 50000
   php_value memory_limit 256M
   php_value session.gc_maxlifetime 36000
   php_value session.save_path "/var/cpanel/php/sessions/ea-php56"
   php_value upload_max_filesize 100M
</IfModule>
# END cPanel-generated php ini directives, do not edit
