RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

# --- アクセス制限ルール ---
RewriteRule ^\.htaccess$ - [F]
RewriteRule ^db\.php$ - [F]
RewriteRule ^settings_admin/CloudflareTurnstile_settings/ - [F]
RewriteRule ^settings_admin/hCaptcha_settings/ - [F]
RewriteRule ^settings_admin/plugin_settings/ - [F]

# --- その他の独自ルーティング ---
RewriteRule ^(@\w+)$ /user/index.php?userid=$1 [QSA,L]
RewriteRule ^@([^@]+)@([^/]+)$ /user/index.php?userid=$1&domain=$2 [QSA,L]
RewriteRule ^!(\w+)~(\w+)$ /ueuse/index.php?ueuseid=$1&touser=$2 [QSA,L]
RewriteRule ^!(\w+)$ /ueuse/index.php?ueuseid=$1 [QSA,L]

# --- エラーハンドリング ---
ErrorDocument 400 /errorpage/httperror.php
ErrorDocument 401 /errorpage/httperror.php
ErrorDocument 403 /errorpage/httperror.php
ErrorDocument 404 /errorpage/httperror.php
ErrorDocument 413 /errorpage/httperror.php
ErrorDocument 500 /errorpage/httperror.php
ErrorDocument 502 /errorpage/httperror.php
ErrorDocument 503 /errorpage/httperror.php

# --- セキュリティヘッダ ---
Header set X-FRAME-OPTIONS "DENY"
