Search code examples
laravel-5http-headerspostmanaccess-tokenapache2.4

Apache drops Authorize header regardless of .htaccess rules resulting 401 on Laravel api request


My code works perfectly fine while I am using it on my local and I can get the user info with postman and I have no issues getting the access token from server or localhost but using the access token for retrieving data from my real server always returns { message: unauthenticated } with status 401

The reason I found out is that Apache Drops the Authorize Header ! I have tried to fix it with adding these to my .htaccess but they don't do any help

my Apache vr is 2.4.29

this is my .htaccess file:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

</IfModule>

Someone please help me with this... :(


Solution

  • It seems the important thing I didn't know was that in first: some shared hosting websites don't allow you to access or modify the apache config file, and second: in the config file its needed to change the AllowOverride from None to All

    AllowOverride All
    

    I switched from a WH4S shared host to a Dreamhosting VPS and everything is working just as it should have been.