大网数据广告活动
服务器运维问答

set header in .htaccess not working if REQUEST_URI contains a word

· 52CE 我爱测

I need to set some headers if REQUEST_URI contains the "compile" word. My uri is: http://myurl/compile/123456/123456?token=myvalue This is the code in the .htaccess that DOES NOT work: Header always set MyHeaderCompile myvalue "e…

问题原文

原帖链接 · Giacomo M · CC BY-SA 4.0

I need to set some headers if REQUEST_URI contains the "compile" word.

My uri is:

http://myurl/compile/123456/123456?token=myvalue

This is the code in the .htaccess that DOES NOT work:

Header always set MyHeaderCompile myvalue "expr=%{REQUEST_URI} =~ /compile/"

This line does not set MyHeaderCompile header.

If I change the line with this:

Header always set MyHeaderCompile myvalue "expr=%{QUERY_STRING} =~ /token/"

It works.

已采纳解答

原帖链接 · Giacomo M · CC BY-SA 4.0

I solved using THE_REQUEST instead of REQUEST_URI.

Thanks to this post https://stackoverflow.com/a/57379503/4641073 I read that REQUEST_URI can be changed from other directives, instead THE_REQUEST never changes.

The line that works is this:

Header always set MyHeaderCompile myvalue "expr=%{THE_REQUEST} =~ /compile/"

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。