I have a laravel site and I'm trying to get everything to work on with SSL.
Though it seems that Laravel wants to use http instead.
For example I was using the form
element and the method was automatically sending to http. The same thing using the built in style
, script
links which I changed all to work statically (regular ol' HTML). The last thing which I can't manage to figure out is the pagination (using jscroll).
I have this row:
{!! $plugins->appends(['tag' => $param2, 'search' => $param1 ])->render() !!}
Which prints this:
<ul class="pager">
<li class="disabled"><span>«</span></li>
<li class="jscroll-next-parent" style="display: none;"><a href="http://siteurl.net/pagename/page/?tag=XXX&search=&page=2" rel="next">»</a>
</li>
</ul>
Any idea how I change that to be https? Thanks!
Try this, go to AppServiceProvider place this code in the boot method:
\URL::forceScheme('https');
The class:
namespace App\Providers;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
URL::forceScheme('https');
}
}
Other way is enforce by .htaccess:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Remember about clearing cache in browser (then htaccess will work correctly).
Good luck!
If you want to generate https routes only (but still plain http requests allowed), change AppServiceProvider:
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
URL::forceScheme('https');
}
}
if you want to redirect any http request to https, add a global middleware:
class ForceHttpsMiddleware{
public function handle($request, Closure $next){
if (!$request->secure() && App::environment() === 'production') {//optionally disable for localhost development
return redirect()->secure($request->getRequestUri());
}
return $next($request);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With