Not receiving X_REQUESTED_WITH request header in Apache localhost

假如想象 提交于 2019-12-13 05:24:24

问题


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).

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.

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?


回答1:


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

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

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



来源:https://stackoverflow.com/questions/20695365/not-receiving-x-requested-with-request-header-in-apache-localhost

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