# Disable directory browsing
Options -Indexes

# ----------------------------------------------------------------------
# Rewrite engine for PHP application routing
# ----------------------------------------------------------------------

<IfModule mod_rewrite.c>
	Options +FollowSymlinks
	RewriteEngine On

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

	# Allow direct access to existing files and directories
	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	RewriteRule ^ - [L]

	# Route main pages through setup.php
	RewriteCond %{QUERY_STRING} ^page=(.*)$
	RewriteRule ^$ setup.php?page=%1 [L,QSA]

	# Default route to setup.php for root access
	RewriteRule ^$ setup.php [L]

	# 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, route to setup.php
	ErrorDocument 404 setup.php
</IfModule>

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