# ============================================
# ATOSK Healthcare Services — URL Rewriting
# Removes .php and .html extensions from URLs
# ============================================

Options -MultiViews
RewriteEngine On

# ===== 1. Redirect trailing .php/.html to clean URL =====
# If someone visits /contact.php, redirect to /contact
RewriteCond %{THE_REQUEST} \s/+(.+?)\.(php|html?)[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

# ===== 2. Redirect trailing slash to no-slash (optional) =====
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_URI} (.+)/$
# RewriteRule ^ %1 [R=301,L]

# ===== 3. Internally rewrite /contact to /contact.php =====
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

# ===== 4. Security: block access to sensitive files =====
<Files "config.php">
  Require all denied
</Files>

<FilesMatch "\.(sql|log|md|ini)$">
  Require all denied
</FilesMatch>

# Block direct access to /includes and /sql folders
RewriteRule ^includes/ - [F,L]
RewriteRule ^sql/ - [F,L]
RewriteRule ^admin/includes/ - [F,L]