# Disable directory browsing
# (was "Options All -Indexes"; "All" also switched on CGI execution and server-side includes)
Options -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
	Options +FollowSymlinks
	RewriteEngine On

	# ------------------------------------------------------------------
	# SECURITY: the web root is the project root, so block everything that
	# is not meant to be public. (Added during the CodeIgniter 4.7.4 upgrade)
	# ------------------------------------------------------------------
	# Hidden files and folders: .env (database passwords!), .git, .htaccess ...
	RewriteRule (^|/)\.(?!well-known/) - [F,L]
	# Framework / private folders and backups
	RewriteRule ^(app|system|writable|tests|vendor|_backup[^/]*|_to_delete)(/|$) - [F,L,NC]

	# If you installed CodeIgniter in a subfolder, you will need to
	# change the following line to match the subfolder you need.
	# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
	# RewriteBase /

	# Redirect Trailing Slashes...
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{REQUEST_URI} (.+)/$
	RewriteRule ^ %1 [L,R=301]

	# Rewrite "www.example.com -> example.com"
	RewriteCond %{HTTPS} !=on
	RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
	RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

	# Checks to see if the user is attempting to access a valid file,
	# such as an image or css document, if this isn't true it sends the
	# request to the front controller, index.php
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

	# Ensure Authorization header is passed along
	RewriteCond %{HTTP:Authorization} .
	RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
	# If we don't have mod_rewrite installed, all 404's
	# can be sent to index.php, and everything works as normal.
	ErrorDocument 404 index.php
</IfModule>

# Block sensitive files anywhere in the site
<FilesMatch "(^\.|\.(env|ini|log|sql|sh|bak|swp|old|orig|dist|lock|md)$|^(composer\.json|composer\.lock|spark|phpunit\.dist\.xml|phpunit\.xml\.dist|preload\.php|LICENSE|env)$)">
	<IfModule authz_core_module>
		Require all denied
	</IfModule>
	<IfModule !authz_core_module>
		Deny from all
	</IfModule>
</FilesMatch>

# Don't advertise the PHP version (security headers for pages are sent by CodeIgniter's "secureheaders" filter)
<IfModule mod_headers.c>
	Header unset X-Powered-By
</IfModule>

# Disable server signature start
	ServerSignature Off
# Disable server signature end

# Redirect HTTP with www to HTTPS with www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTP without www to HTTPS with www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTPS without www to HTTPS with www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# php -- BEGIN cPanel-generated handler, do not edit
# CodeIgniter 4.7 needs PHP 8.2 or newer. PHP 8.0 (ea-php80) will NOT work.
# Set the “ea-php83” package as the default “PHP” programming language.
# (If your host does not offer ea-php83, choose PHP 8.2+ in cPanel > MultiPHP Manager.)
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php83 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
