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

Change Underscore to Dash in Apache Header

· 52CE 我爱测

I have an application that runs behind Apache 2.4.27 that authenticates users with mod_auth_cas. This module stores attributes about the authenticated user in headers. I'm having issues with one header that's being stripped becau…

问题原文

原帖链接 · Ross · CC BY-SA 3.0

I have an application that runs behind Apache 2.4.27 that authenticates users with mod_auth_cas. This module stores attributes about the authenticated user in headers. I'm having issues with one header that's being stripped because it has an underscore in it (X-CAS-email_primary). After doing some searching, I added the code snippet below to the VirtualHost configuration.

SetEnvIfNoCase X-CAS-email_primary ^(.*)$ fix_header=$1
RequestHeader set X-CAS-email-primary %{fix_header}e env=fix_header

In case it wasn't obvious, I'm trying to change X-CAS-email_primary to X-CAS-email-primary. This code is partially working. The new header does appear but it has no value.

["HTTP_X_CAS_EMAIL_PRIMARY"]=> string(0) ""

I've confirmed that X-CAS-email_primary is set, so I'm not quite sure what's going on. Any suggestions?

Thanks!

已采纳解答

原帖链接 · Andrew Schulman · CC BY-SA 3.0

The value of a RequestHeader set supports expressions, and expressions include the req (or http) function, which gives you the value of request headers. So this one directive should do what you want:

RequestHeader set X-CAS-email-primary "expr=%{req:X-CAS-email_primary}"

You have to dig deep into the documentation to find this kind of thing, but it's there.

Not sure why your configuration didn't work, but I guess the SetEnvIfNoCase is evaluated after the RequestHeader. The docs don't make it easy to figure that out.

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

资料来源与适用范围

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

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

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