0

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 Answers1

0

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.

Liam W
  • 1,193
  • 1
  • 26
  • 46
  • Thanks for your help, Liam. For clarity, here is what I added to my .htaccess file. You also have to make sure you have the mod_setenvif and mod_headers modules enabled. `SetEnvIfNoCase ^X.REQUESTED.WITH$ ^(.*)$ fix_accept_encoding=$1 RequestHeader set X-REQUESTED-WITH %{fix_accept_encoding}e env=fix_accept_encoding` – revengeoftheants Feb 26 '14 at 02:39