Custom HTTP Header for a specific file

折月煮酒 提交于 2019-12-12 17:34:27

问题


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

Many thanks in advance!

Cheers, Stefan


回答1:


In a Files directive, you can not match against file path, you can match against filename.ext only

<Files "serviceworker.js">
Header Set Service-Worker-allowed "/"
</Files>

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



来源:https://stackoverflow.com/questions/42316222/custom-http-header-for-a-specific-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!