Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I was trying to prevent PHP from parsing POST requests. It does automatically when it sees the according MIME type. For that I was considering following RewriteRule hack:

RewriteCond %{HTTP:Content-Type} ^(multipart/form-data\s*;.*)$   
RewriteRule mime.php - [E=CONTENT_TYPE:no/parsing;old=%1]

But the CGI environment still contains the original [CONTENT_TYPE] => multipart/form..

  • I could set e.g. ALT_CONTENT_TYPE troublefree, but that's no use to me, because PHP still acts on the original then.
  • Likewise changing the case [E=ContEnt_Type] will not remove the old header value, it just changes the case really.
  • Is the CONTENT_TYPE env var constructed at a later stage? Because I also had trouble accessing it as just %{CONTENT_TYPE}. But on a second look, the docs http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond didn't mention it anyway.

Is there another way to override this CGI variable?

local testserver:

 Server version: Apache/2.2.14 (Ubuntu)
 mod_php, not fastcgi
 Linux snig 2.6.32-29-generic #58-Ubuntu SMP, 2011 x86_64 GNU/Linux
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted
+50

This answer suggests an Apache solution:

<Location "/backend/XXX.php">
    SetEnvIf Content-Type ^(multipart/form-data)(.*) NEW_CONTENT_TYPE=multipart/form-data-alternate$2 OLD_CONTENT_TYPE=$1$2
    RequestHeader set Content-Type %{NEW_CONTENT_TYPE}e env=NEW_CONTENT_TYPE
</Location> 
share|improve this answer
    
That works. Needs an a2enmod headers though. So maybe not workable on all servers. (But the existence of that specific module makes a simpler solution unlikely.) –  mario Apr 12 '11 at 21:44
    
Rewriting may require an a2enmod rewrite, so it's no more or less workable on principle. –  crb Apr 13 '11 at 11:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.