Laravel 5分页与重定向动作跳转至HTTPS而非HTTP的问题求助
Hey there, let's sort out this frustrating issue where your pagination links and redirects are forcing HTTPS instead of HTTP in Laravel 5. I've dealt with similar quirks before, so here are actionable fixes to try:
1. Check Server Configuration Headers
Sometimes your web server (Apache, Nginx, etc.) sends incorrect protocol headers that trick Laravel into thinking it's running on HTTPS.
- For Nginx: Look for lines like
fastcgi_param HTTPS on;in your site config. If you're running on HTTP, remove or comment this line. - For Apache: Check if there's an
SetEnv HTTPS ondirective in your.htaccessor virtual host config that shouldn't be there.
2. Update Laravel's Application URL Settings
Laravel uses the APP_URL value to generate URLs by default.
- Open your
.envfile and make sureAPP_URLis set to your HTTP address:APP_URL=http://your-domain.com - Double-check the fallback in
config/app.php:
Ensure the default here is HTTP, not HTTPS.'url' => env('APP_URL', 'http://localhost'),
3. Force HTTP Directly in Your Code
If you need a quick fix for specific links/redirects, you can explicitly set the protocol:
- Pagination links: Use the
setScheme()method to force HTTP:{!! $list->appends($form)->setScheme('http')->links() !!} - Redirects: Instead of using
action(), useto()with the full HTTP URL, or use theurl()helper with the protocol specified:
The third parameter// Option 1: Full URL return redirect()->to('http://your-domain.com/route/' . $testId); // Option 2: Using url() helper return redirect(url('route-name', [$testId], false));falseinurl()disables HTTPS enforcement.
4. Check for HTTPS-Enforcing Middleware
Take a look at your app/Http/Kernel.php file to see if any middleware is forcing HTTPS redirects. This could be a custom middleware or a third-party package. If you find one, either remove it or adjust its logic to only apply when needed.
内容的提问来源于stack exchange,提问作者Jaydeep Mor

