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

Laravel 8升级后配置HTTPS,Laravel-admin登录跳转至根目录求助

Troubleshooting Laravel-Admin Redirect to Root After Login on HTTPS

Hey there, let's work through this redirect issue you're hitting after logging into your laravel-admin panel on the server. Local works fine, but HTTPS via .htaccess is causing a jump to the root—here are the most likely fixes:

1. Fix Your APP_URL Environment Variable

The first thing to check is your .env file. Since you're now using HTTPS on the server, Laravel needs to know the correct secure base URL to generate proper redirects.

  • Open your .env file and update APP_URL to use HTTPS:
    APP_URL=https://your-domain.com
    
  • Then clear Laravel's config and application cache to apply the change:
    php artisan config:cache
    php artisan cache:clear
    

Laravel-admin relies heavily on the APP_URL for generating internal links, so a mismatch here is a common culprit for weird redirects.

2. Adjust Your .htaccess Rules

Your current HTTPS redirect rule might be interfering with Laravel's internal routing, especially during the login POST request. Let's reorder the rules to prioritize HTTPS redirect before Laravel's rewrite logic, and ensure all request parameters are preserved:

Replace your existing .htaccess content with this:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Enforce HTTPS first
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Laravel's default rewrite rules (keep these intact)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Also, double-check that your server has mod_rewrite enabled, and that the directory's AllowOverride setting is set to All in your Apache config—otherwise the .htaccess rules won't apply.

3. Secure Session Cookies for HTTPS

When switching to HTTPS, session cookies should be marked as secure to prevent them from being sent over unencrypted connections. This can sometimes cause session loss after login, leading to unexpected redirects.

  • Open config/session.php and update the secure option:
    'secure' => env('SESSION_SECURE_COOKIE', true),
    
  • Then add this to your .env file:
    SESSION_SECURE_COOKIE=true
    

This ensures cookies are only sent over HTTPS, keeping your sessions secure and avoiding issues that trigger redirects.

4. Clear Browser Cache and Cookies

301 redirects are cached by browsers aggressively. Even if you fix the server-side issues, old cached redirects might still cause problems. Clear your browser's cache and cookies for your domain, then test the login again.

5. Verify Laravel-Admin's Redirect Configuration

Double-check your laravel-admin config to make sure the post-login redirect is set correctly. Open config/admin.php and look for the redirect_to option:

'redirect_to' => 'admin/dashboard',

This should be a relative path (not an absolute HTTP URL) so it uses your APP_URL to build the correct HTTPS link.

If you try these steps one by one, you should be able to resolve the redirect issue. Let me know if any of these don't work!

内容的提问来源于stack exchange,提问作者saber tabatabaee yazdi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 18:58:12