You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 5分页与重定向动作跳转至HTTPS而非HTTP的问题求助

Fixing Unwanted HTTPS Redirects in Laravel 5

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 on directive in your .htaccess or 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 .env file and make sure APP_URL is set to your HTTP address:
    APP_URL=http://your-domain.com
    
  • Double-check the fallback in config/app.php:
    'url' => env('APP_URL', 'http://localhost'),
    
    Ensure the default here is HTTP, not HTTPS.

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(), use to() with the full HTTP URL, or use the url() helper with the protocol specified:
    // 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));
    
    The third parameter false in url() 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:10:27