【问题标题】:htaccess header not applied on http filehtaccess 标头未应用于 http 文件
【发布时间】: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


    【解决方案1】:

    这个问题很可能是因为使用了here 中描述的 php fastcgi。我正在使用托管服务,因此无法更改配置,但使用 header command 在 PHP 代码中添加标头效果很好。

    【讨论】:

      猜你喜欢
      • 2016-10-16
      • 2018-02-02
      • 2014-07-10
      • 2011-01-09
      • 2021-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多