<IfModule mod_rewrite.c>
    RewriteEngine On
    
    RewriteRule ^(.*)$ public/$1 [L]
    
    RewriteBase /

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

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

# ----------------------------------------------------------------------
# PHP Configuration Overrides (Optimized for Laravel)
# ----------------------------------------------------------------------
<IfModule php8_module>
    php_value max_execution_time 400
    php_value max_input_time 600
    php_value memory_limit 512M
    php_value post_max_size 50M
    php_value upload_max_filesize 50M
    php_value max_input_vars 5000
    php_value allow_url_fopen On
    php_flag display_errors Off
</IfModule>

# For LiteSpeed or LSAPI (if used on your host)
<IfModule lsapi_module>
    php_value max_execution_time 400
    php_value max_input_time 600
    php_value memory_limit 512M
    php_value post_max_size 50M
    php_value upload_max_filesize 50M
    php_value max_input_vars 5000
    php_value allow_url_fopen On
    php_flag display_errors Off
</IfModule>

# ----------------------------------------------------------------------
# Security Headers (Recommended)
# ----------------------------------------------------------------------
<IfModule mod_headers.c>
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-Content-Type-Options "nosniff"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
    Header set X-XSS-Protection "1; mode=block"
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</IfModule>

# ----------------------------------------------------------------------
# GZIP Compression (If supported by Apache)
# ----------------------------------------------------------------------
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json
</IfModule>

# ----------------------------------------------------------------------
# Browser Caching (Improves Frontend Performance)
# ----------------------------------------------------------------------
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 2 days"
</IfModule>

# ----------------------------------------------------------------------
# Prevent Directory Browsing
# ----------------------------------------------------------------------
Options -Indexes

# ----------------------------------------------------------------------
# Disable Access to Hidden Files (.env, .git, etc.)
# ----------------------------------------------------------------------
<FilesMatch "^\.">
    Require all denied
</FilesMatch>

# ----------------------------------------------------------------------
# Ensure mod_rewrite Is Enabled
# ----------------------------------------------------------------------
<IfModule !mod_rewrite.c>
    ErrorDocument 500 "Error: Apache mod_rewrite is not enabled. Please contact your hosting provider."
</IfModule>

# 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_flag display_errors Off
   php_value max_execution_time 400
   php_value max_input_time 600
   php_value max_input_vars 1000
   php_value memory_limit 128M
   php_value post_max_size 50M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php83"
   php_value upload_max_filesize 50M
   php_flag zlib.output_compression On
</IfModule>
<IfModule lsapi_module>
   php_flag display_errors Off
   php_value max_execution_time 400
   php_value max_input_time 600
   php_value max_input_vars 1000
   php_value memory_limit 128M
   php_value post_max_size 50M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php83"
   php_value upload_max_filesize 50M
   php_flag zlib.output_compression On
</IfModule>
# END cPanel-generated php ini directives, do not edit

# 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
