0

We created a couple of custom API's that are working fine on localhost, but on the server one of them give's internal server error.

In the error log we got this:

[Fri Jul 14 16:06:46.397538 2017] [core:error] [pid 7894:tid 139744927274752] [client 5.2.174.151:40133] malformed header from script 'index.php': Bad header: content-type

In the API we set the header content type to application/json

<?php header('content-type','application/json'); ?>

The php versions on localhost and server are the same 5.6.31

And this is the htaccess:

DirectoryIndex index.php

<IfModule mod_php5.c>
php_value memory_limit 768M
php_value max_execution_time 18000
php_flag session.auto_start off
php_flag suhosin.session.cryptua off
</IfModule>

<IfModule mod_php7.c>
php_value memory_limit 768M
php_value max_execution_time 18000
php_flag session.auto_start off
php_flag suhosin.session.cryptua off
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_ssl.c>
SSLOptions StdEnvVars
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
AddDefaultCharset Off
AddType 'text/html; charset=UTF-8' html
<IfModule mod_expires.c>
ExpiresDefault "access plus 1 year"
ExpiresByType text/html A0
ExpiresByType text/plain A0
</IfModule>
RedirectMatch 403 /\.git
<Files composer.json>
    order allow,deny
    deny from all
</Files>
<Files composer.lock>
    order allow,deny
    deny from all
</Files>
<Files .gitignore>
    order allow,deny
    deny from all
</Files>
<Files .htaccess>
    order allow,deny
    deny from all
</Files>
<Files .htaccess.sample>
    order allow,deny
    deny from all
</Files>
<Files .php_cs>
    order allow,deny
    deny from all
</Files>
<Files .travis.yml>
    order allow,deny
    deny from all
</Files>
<Files CHANGELOG.md>
    order allow,deny
    deny from all
</Files>
<Files CONTRIBUTING.md>
    order allow,deny
    deny from all
</Files>
<Files COPYING.txt>
    order allow,deny
    deny from all
</Files>
<Files Gruntfile.js>
    order allow,deny
    deny from all
</Files>
<Files LICENSE.txt>
    order allow,deny
    deny from all
</Files>
<Files LICENSE_AFL.txt>
    order allow,deny
    deny from all
</Files>
<Files nginx.conf.sample>
    order allow,deny
    deny from all
</Files>
<Files package.json>
    order allow,deny
    deny from all
</Files>
<Files php.ini.sample>
    order allow,deny
    deny from all
</Files>
<Files README.md>
    order allow,deny
    deny from all
</Files>
<Files magento_umask>
    order allow,deny
    deny from all
</Files>
ErrorDocument 404 /pub/errors/404.php
ErrorDocument 403 /pub/errors/404.php
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=edge"
<FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
    Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
<IfModule mod_headers.c>
# with AJAX withCredentials=false (cookies NOT sent)
Header always set Access-Control-Allow-Origin "*"  
Header always set Access-Control-Allow-Credentials  "true"              
Header always set Access-Control-Allow-Methods "POST, GET, PUT, PATCH, DELETE, OPTIONS"
Header always set Access-Control-Allow-Headers "Content-Type, Authorization"
RewriteEngine On                  
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L,E=HTTP_ORIGIN:%{HTTP:ORIGIN}]]
# RewriteRule ^(.*)$ $1 [R=200,L]

Any suggestion will be highly appreciated, thank you.

4
  • Can you post what the actual header value comes out as? sometimes it gets UTF8 automatically added, and some (dumb) systems choke on that. Commented Jul 14, 2017 at 15:35
  • Hi, sorry for this late response, I get this info from header when I call the url of the API. Array ( [0] => HTTP/1.1 200 OK [1] => Date: Mon, 17 Jul 2017 08:05:51 GMT [2] => Server: Apache [3] => Last-Modified: Mon, 17 Jul 2017 07:56:23 GMT [4] => Accept-Ranges: bytes [5] => Content-Length: 3268 [6] => Connection: close [7] => Content-Type: text/html ) 1 exception(s): Exception #0 (Exception): Warning: Cannot modify header information - headers already sent Commented Jul 17, 2017 at 8:08
  • Interesting... And you don't get that exception on localhost? Commented Jul 17, 2017 at 12:00
  • Nope, I don't get that exception on localhost, there everything seems to work fine. It's very strange... Commented Jul 18, 2017 at 6:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.