# Enable RewriteEngine
RewriteEngine On

# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Remove .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# Custom error pages
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php

# Protect sensitive files
<FilesMatch "^(config|install)\.php$">
    Order allow,deny
    Deny from all
    Allow from 127.0.0.1
</FilesMatch>

# Prevent directory browsing
Options -Indexes

# Protect .htaccess
<Files .htaccess>
    Order allow,deny
    Deny from all
</Files>

# Set timezone
SetEnv TZ Asia/Tehran

# PHP settings
php_flag display_errors Off
php_flag log_errors On
php_value max_execution_time 300
php_value upload_max_filesize 10M
php_value post_max_size 10M

# Compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
</IfModule>

# Browser caching
<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 application/javascript "access plus 1 month"
</IfModule>

