# ============================================
# URL REDIRECTS
# ============================================

RewriteEngine On

# Force the production canonical host and HTTPS.
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^innovarerenovations\.com\.au$ [NC]
RewriteRule ^ https://innovarerenovations.com.au%{REQUEST_URI} [R=301,L]

# Dynamic XML sitemap.
RewriteRule ^sitemap\.xml$ sitemap.php [L]

# Redirect index.html to the root domain
RewriteCond %{THE_REQUEST} \s/+index\.html[\s?] [NC]
RewriteRule ^index\.html$ https://innovarerenovations.com.au/ [R=301,L]

# Redirect the public PHP page to its extensionless canonical URL.
RewriteCond %{THE_REQUEST} \s/+contact\.php[\s?] [NC]
RewriteRule ^contact\.php$ /contact [R=301,L]

# Redirect .html URLs to extensionless URLs
# Example: /about.html -> /about
RewriteCond %{THE_REQUEST} \s/+(.+)\.html[\s?] [NC]
RewriteRule ^(.+)\.html$ /$1 [R=301,L]

# Remove trailing slashes from non-directory public URLs.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]

# ============================================
# SERVE .html FILES WITHOUT SHOWING .html
# ============================================

# If /about is requested, internally load /about.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

# If /contact is requested, internally load /contact.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

# ============================================
# SEO RESPONSE HEADERS
# ============================================

<IfModule mod_headers.c>
  <FilesMatch "^(contact-data\.php|.*\.(zip|md|docx))$">
    Header set X-Robots-Tag "noindex, nofollow, noarchive"
  </FilesMatch>
</IfModule>

# Process existing .html pages through PHP so the shared head template can run.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php82 .html .htm
</IfModule>

# ============================================
# BEGIN cPanel-generated php ini directives
# ============================================

# 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 php8_module>
   php_value error_log "/home/innovare/logs/php.error.log"
   php_flag log_errors On
</IfModule>

<IfModule lsapi_module>
   php_value error_log "/home/innovare/logs/php.error.log"
   php_flag log_errors On
</IfModule>

# END cPanel-generated php ini directives


# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php82” package as the default “PHP” programming language.

<IfModule mime_module>
  AddHandler application/x-httpd-ea-php82 .php .php8 .phtml
</IfModule>

# php -- END cPanel-generated handler, do not edit
