# ================================================
# Centre Stage Entertainment - Production .htaccess
# CRITICAL: PHP Handler Configuration for cPanel/EasyApache
# ================================================

# Force PHP 8.1 execution with EasyApache handler
<FilesMatch "\.php$">
    SetHandler application/x-httpd-ea-php81
</FilesMatch>

# Fallback handlers
AddHandler application/x-httpd-ea-php81 .php
AddType application/x-httpd-php .php

# Enable mod_rewrite for React SPA routing
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # CRITICAL: Explicitly allow contact.php and test-php.php to be executed
    RewriteRule ^(contact|test-php)\.php$ - [L]

    # Don't rewrite existing files (images, css, js, etc.)
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    # Don't rewrite existing directories
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Rewrite all other requests to index.html for React Router
    RewriteRule ^ index.html [L]
</IfModule>

# Security headers
<IfModule mod_headers.c>
    # CORS headers for contact form
    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "POST, GET, OPTIONS"
    Header set Access-Control-Allow-Headers "Content-Type, Authorization"
</IfModule>

# Handle CORS preflight OPTIONS requests
<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ $1 [R=200,L]
</IfModule>

# Ensure proper MIME types
<IfModule mod_mime.c>
    AddType application/x-httpd-ea-php81 .php
</IfModule>

# Prevent directory browsing
Options -Indexes