在Apache localhost中未收到X_REQUESTED_WITH请求标头 [英] Not receiving X_REQUESTED_WITH request header in Apache localhost

查看:124
本文介绍了在Apache localhost中未收到X_REQUESTED_WITH请求标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Windows 7桌面上设置了32位Apache 2.4,并且正在测试一个简单的AJAX网站.我有一个.htaccess文件,该文件将所有非资源文件请求都定向到index.php,并且在此.php脚本中,我检查$_SERVER["HTTP_X_REQUESTED_WITH"]以确定给定的请求是否为ajax(我在发送时自行设置了此标头ajax请求).

I just set up Apache 2.4 32-bit on my Windows 7 desktop and I am testing a simple AJAX website. I have an .htaccess file that directs all non-resource-file requests to index.php, and within this .php script I check $_SERVER["HTTP_X_REQUESTED_WITH"] to determine if a given request is ajax or not (I set this header myself when I send the ajax request).

尽管已设置标头,但Apache似乎在我的.php脚本运行之前将其删除.我可以在Chrome中看到请求标头,但.php脚本中没有.我什至尝试在Apache的access.log中记录\"%{X_REQUESTED_WITH}i\",但是我也看不到它.

Though the header is getting set, Apache seems to be dropping it before my .php script runs. I can see the request header in Chrome, but it's not there in the .php script. I even tried logging \"%{X_REQUESTED_WITH}i\" in Apache's access.log, but I don't see it there either.

当网站在Bluehost上运行时,此功能有效.我需要配置Apache使其在我的本地计算机上工作吗?

This functionality works when the site is running on Bluehost. Do I need to configure Apache to get it to work on my local machine?

推荐答案

出于安全性考虑,Apache 2.4现在会删除所有带有下划线的标头.

Apache 2.4 now drops all headers with underscores, for 'security' reasons.

根据他们的文档,您可以通过将其添加到htaccess中来添加它们:

According to their docs, you can add them by adding this to your htaccess:

SetEnvIfNoCase ^Accept.Encoding$ ^(.*)$ fix_accept_encoding=$1
RequestHeader set Accept-Encoding %{fix_accept_encoding}e env=fix_accept_encoding

其中Accept.Encoding和Accept-Encoding是标题名称.下划线分别替换为点和连字符.

Where Accept.Encoding and Accept-Encoding is the header name. Underscores are replaced with dots and hyphens respectively.

这篇关于在Apache localhost中未收到X_REQUESTED_WITH请求标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆