strange response headers in laravel app using JWT [duplicate] - laravel

I deployed my laravel project on a shared hosting server that supports mod_rewrite and want to send a header called Authorization (JWT header) but it wont reach the controller.
mt .htaccess:
Options -MultiViews -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

To evade Apache2 discards the authorization header I needed to add this code:
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
To my .htcaccess file in my /public folder.

Related

Laravel 8 Redirect Http to Https

I'm starting to develop a new big app, and I'm using Laravel 8 this time, and it's the first time.
I trying to Redirect HTTP to HTTPS with .htaccess file but unfortunately it's not working https://app.workfromhere.com.my/ please help me thanks.
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I found out you are using cPanel, you can set Force HTTPS Redirect in Domains tap.

HTTPS redirects on Heroku Laravel not working correctly

I tried to force HTTPS on subdomain Heroku/Laravel. See .htaccess below.
It didn't work. Instead the subdomain "https://sub.domain.com/anything" redirect to "https://sub.sub.domain.com/index.php". See the double "sub" and the "index.php" in the URL?
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# If we receive a forwarded http request from a proxy...
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
# ...or just a plain old http request directly from the client
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
# Redirect to https version
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Could you please try following htaccess file. Based on your shown samples only, have changed the sequence of your Rules(couldn't test it). Please make sure you clear your browser cache before testing any URLs.
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# If we receive a forwarded http request from a proxy...
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
# ...or just a plain old http request directly from the client
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
# Redirect to https version
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
An alternative and better solution is to force HTTPS in Laravel directly and not in NGINX.
This way Laravel generates directly HTTPS URLs, and you don't have to redirect it.
To force HTTPS in Laravel you should add the following inside App\Providers\AppServiceProvider:
/**
* Bootstrap any application services.
*/
public function boot()
{
if (!App::environment([
'local',
'testing',
])) {
URL::forceScheme('https');
}
}

Laravel MethodNotAllowedHttpException The GET method is not supported for this route. Supported methods: POST

I have Laravel project works as an API, On my local machine it's working currectly but when I uploaded it on the server and send a request with Postman it doesn't send a post request, It's changed to GET request ! I read so many solutions and nothing worked for me.
https://imgur.com/p44fI1W
https://imgur.com/gdVLhXk
https://imgur.com/RKDpEom
My .htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

How to fix .htaccess issue in Laravel 5.8

I am trying to change .htaccess file.But changes are not reflecting. Laravel home page works properly even if .htaccess file contains errors.
I have gone through the checking of mod_rewrite enable and apache2.conf files.Everything is perfect but unable to find the issue.
gfdghfguf;l;..
hfjffgfgh
lghkjgkjg
jfghkfhjfgh ghggggggggggggb
Options -MultiViews -Indexes
RewriteEngine On
gb gjf jfhgj jfhg jhfjf g
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
It have to give 500 internal server error but it works fine.

redirect to secure connection thru .htaccess / exception admin location / framework Laravel

I want to redirect http to https and in addition I have to remove admin location because it does not work with https.
The site uses the Laravel framework.
At the code below I need to add the restriction:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com
RewriteRule ^(.*)$ https://www.website.com/$1 [R,L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This will do it for you:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
The second RewriteCond stops the rewrite from happening if it is the /admin/ URI. The redirection is done using R=301 which is a permanent redirection, for testing purposes I advise you change this to R=302 as this is temporary.
Make sure you clear your cache before testing this.

Resources