# ==========================================
# UNIVERSAL HTACCESS (403 FIXED)
# Works on: Hostinger, cPanel, VPS, Localhost
# ==========================================

# --- Enable rewrite engine safely --- 
<IfModule mod_rewrite.c>
RewriteEngine On

# Automatically set correct base path
RewriteBase /

# ✅ Add .php extension automatically
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9/_-]+)$ $1.php [NC,L]

# ✅ Block access to admin panels (but no 403)
RewriteCond %{REQUEST_URI} ^/(admin|cadmin|capanle|hpanle|mpanle)/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /404.html [L]

# ✅ Redirect all other unknown URLs to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]
</IfModule>

# ==========================================
# SECURITY (SAFE FOR ALL HOSTINGS)
# ==========================================

# Disable directory listing
Options -Indexes

# --- Secure sensitive file types ---
<FilesMatch "\.(zip|json|env|sql|ini|bak|conf|config|log|sh|crt|pem)$">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Deny from all
  </IfModule>
</FilesMatch>

# --- Allow 404 page ---
<Files 404.shtml>
  <IfModule mod_authz_core.c>
    Require all granted
  </IfModule>
  <IfModule !mod_authz_core.c>
    Allow from all
  </IfModule>
</Files>

# (REMOVED RedirectMatch 403 aur <Directory> section jo 403 cause karta tha)

# ==========================================
# PHP CONFIG (UNIVERSAL)
# ==========================================
<IfModule mod_php.c>
  php_flag display_errors Off
  php_value upload_max_filesize 20M
  php_value post_max_size 20M
  php_value memory_limit 256M
  php_value max_execution_time 90
  php_value max_input_time 90
</IfModule>

# ==========================================
# UNIVERSAL PHP HANDLER (AUTO DETECT)
# ==========================================
<IfModule mime_module>
  AddHandler application/x-httpd-php .php .php7 .php8 .phtml
</IfModule>

# ==========================================
# END OF FILE
# ==========================================
