3

I am using Laravel 7 and website is running on https but it shows all links to http.

i am using below code to redirect for all pages.

<a href="{{url('about')}}">About></a>

5 Answers 5

6

in config/app.php you should have a url entry to set like:

'url' => 'https://your-website.domain'

otherwise you can use the boot method of AppServiceProvider adding this:

\URL::forceScheme('https');
Sign up to request clarification or add additional context in comments.

6 Comments

Hey Alberto, Thanks let me try this and get back to you.
@Amit sure, let me know
Hey Alberto its https with domain name already there. No Luck
have you tried with the second snipped? @Amit
@Amit literally search for a file called AppServiceProvider and inside the boot method (that you will see inside that file) add that line of code
|
4

I had the same issue when running a Laravel application behind an NGINX proxy and the communication internally was running via HTTP. So, the request reached Laravel as HTTP.

The solution from Alberto was fixing it. Here is the code I have added to the boot() method of the AppServiceProvider:

if (config('app.env') === 'production' || config('app.env') === 'staging') {
    URL::forceScheme('https');
}

Comments

0

I am testing telegram bot with ngrok forwarding, and always edit APP_URL in my env file

and sometimes I testing local http://localhost:81

My solution in the boot() method of the AppServiceProvider

use Illuminate\Support\Facades\URL;

if (mb_strpos(env('APP_URL'), 'https') === 0) {
    URL::forceScheme('https');
}

2 Comments

So, the difference between this and Albert's answer is that this logic checks the APP_URL environment variable before calling URL::forceScheme where Albert's code calls it unconditionally.
@SmellyCat yes, for me very helpful when you test project on localhost, or dev server with SSL
0

@V-E-Y is right. The better way to enforce HTTPS in Laravel when using Nginx is by configuring the headers like this:

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

Comments

-1

Hey all who use NGINX proxy

Don't use URL::forceScheme('https');

Just add: proxy_set_header X-Forwarded-Proto $scheme;

location / {
    ...
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }

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.