1

Laravel Project I have created a custom Postman header called company_code, and it works on my local development environment on my PC. However, when I deploy this project on a live server, the custom headers are not being received from the Laravel middleware.

Added company_code custom header

I am unable to retrieve the company_code from the Laravel middleware.

I tried using store value in larave config files but it's not working. I want how to access custom header in laravel project on live server.

2
  • "the custom headers are not being received from the Laravel middleware" - this can depend on how the app is being hosted. What is the webserver config like? Is it sitting behind a load balancer? etc... Commented Sep 11, 2024 at 8:14
  • So, what's the solution for this? i have uploaded project on aapanel and using apache web server. Commented Sep 11, 2024 at 8:52

1 Answer 1

3

You have to update your server configuration. Assuming you're on an Apache server, you have to update the .htaccess file to include the following rule.

RewriteCond %{HTTP:company_code} ^(.*)
RewriteRule .* - [e=HTTP_COMPANY_CODE:%1]

The Reason -

By default, Apache doesn't pass all HTTP headers to the application server. It only passes a standard set of headers. By adding the rewrite rule for "company_code", you're telling Apache - "If you see a header called "company_code", please make it available to the PHP application as if it were a standard header."

Sign up to request clarification or add additional context in comments.

Comments

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.