【发布时间】:2021-06-28 15:05:14
【问题描述】:
我想使用 htaccess 文件添加 HTTP 响应标头,但它不适用于主文件,而所有资源(如 css 和 img 文件)都获取该标头。我的 htaccess 文件如下所示:
RewriteEngine On
Header always set test-header "value"
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# 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]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://myurl.goes.here/$1 [R,L]
</IfModule>
我尝试在文件中的不同位置移动“标题集”行,但这没有帮助。
【问题讨论】:
标签: apache .htaccess http-headers