Not receiving X_REQUESTED_WITH request header in A

2019-09-11 14:01发布

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条回答
Fickle 薄情
2楼-- · 2019-09-11 14:27

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.

查看更多
登录 后发表回答