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

Laravel部署后如何将密码重置链接中的localhost替换为域名?

This is a super common issue in Laravel, and it almost always boils down to configuration or caching. Here's how to fix it step by step:

1. Update Your .env File

The first thing to check is your APP_URL environment variable. Laravel uses this value to generate absolute URLs in emails (like password reset links). Open your .env file and make sure it's set to your actual domain:

APP_URL=https://mydomain

Note: Use http:// if you haven't set up SSL yet, but HTTPS is always recommended for production.

2. Clear Configuration Cache

Laravel caches configuration values to boost performance, so even if you update .env, the old localhost value might still be stored in the cache. Run these terminal commands to clear and refresh your config cache:

php artisan config:clear
php artisan config:cache # Optional, but recommended for production environments

3. Verify Your Custom Password Reset Notification (If Used)

If you've created a custom password reset notification instead of using Laravel's default one, double-check that you're using the correct URL helpers. The default notification uses url() with the route helper, which pulls the APP_URL value automatically:

// Example from the default ResetPassword notification
return (new MailMessage)
    ->line('You are receiving this email because we received a password reset request for your account.')
    ->action('Reset Password', url(route('password.reset', [
        'token' => $this->token,
        'email' => $notifiable->getEmailForPasswordReset(),
    ])))
    ->line('If you did not request a password reset, no further action is required.');

Avoid hardcoding localhost anywhere in this file—stick to using Laravel's built-in helpers to generate dynamic, correct URLs.

4. Check Mail Driver Configuration (Rare Edge Case)

If you're using a third-party mail service (like Mailgun or SendGrid), ensure you haven't set any domain-specific overrides in their configuration that might be altering the link. This is less likely since Laravel handles URL generation before passing content to the mail driver, but it's worth a quick check if the above steps don't work.

After following these steps, test the password reset flow again—your links should now point to https://mydomain/password/reset/... instead of localhost.

内容的提问来源于stack exchange,提问作者user9463040

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:26:44