tp/public/.htaccess
2026-03-12 17:53:36 +08:00

25 lines
905 B
ApacheConf

# Apache/.htaccess CORS 配置
<IfModule mod_rewrite.c>
RewriteEngine On
# 处理 OPTIONS 预检请求
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=204,L]
# 排除静态文件和特定PHP文件
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/themes/
RewriteCond %{REQUEST_URI} !^/static/
RewriteCond %{REQUEST_URI} !^/storage/
RewriteCond %{REQUEST_URI} !^/favicon.ico$
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteRule ^(.*)$ index.php [L]
# 添加 CORS 头
Header set Access-Control-Allow-Origin "http://localhost:5173"
Header set Access-Control-Allow-Credentials "true"
Header set Access-Control-Allow-Methods "GET, POST, PATCH, PUT, DELETE, OPTIONS"
Header set Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With"
</IfModule>