特定文件的自定义HTTP标头 [英] Custom HTTP Header for a specific file
问题描述
我正在尝试通过我的htaccess文件为特定文件设置标头,以便让我的服务工作者访问我的root。不幸的是我没有看到标题出现......也许我没有定位文件( https://www.stefanklokgieters.nl/wp-content/themes/stefanklokgieters/serviceworker.js )正确吗?
I am trying to set a header for a specific file via my htaccess file in order to give my service worker access to my root. Unfortunately I don't see the header appearing... Perhaps I am not targeting the file (https://www.stefanklokgieters.nl/wp-content/themes/stefanklokgieters/serviceworker.js) correctly?
# Add custom header to single file
<Files "/wp-content/themes/stefanklokgieters/serviceworker.js">
Header set Service-Worker-Allowed "/"
</Files>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
非常感谢提前!
干杯,
Stefan
Cheers, Stefan
推荐答案
在 Files
指令,你无法比拟对于文件路径,您只能与 filename.ext 匹配
<Files "serviceworker.js">
Header Set Service-Worker-allowed "/"
</Files>
将此项放入相应子目录中的.htaccess文件中,以将其限制在此路径中,例如 /path/to/wp-content/themes/stefanklokgieters/.htaccess
Put this in an .htaccess file in the appropriate subdirectory, to restrict it to this path only, e.g. /path/to/wp-content/themes/stefanklokgieters/.htaccess
这篇关于特定文件的自定义HTTP标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!