hotantien
  • Laravel
  • WordPress
  • SEO
  • Đồ họa
  • Javascript
  • Download
  • Công cụ
No Result
View All Result
hotantien
No Result
View All Result
Home Laravel

https trong Laravel

in Laravel

Chuyển từ HTTP sang HTTPS trong Laravel

Nội dung bài viết

  1. Cấu hình
  2. Force HTTPS for All Routes
  3. Force HTTPS for Pagination Links

Cấu hình

Đầu tiên bạn phải đảm bảo hosting/sever của bạn có hỗ trợ hoặc đã cài đặt SSL cho tên miền. Sau đó, mở tệp .env và đặt liên kết HTTPS của trang web của bạn thành APP_URL:

APP_URL=https://domain.com

Các bạn nên thể xóa cache sau khi cập nhật file .env

php artisan cache:clear
php artisan config:cache

Apache

Nếu ứng dụng của bạn đang chạy trên Apache Sever thì cập nhật file .htaccess

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Nginx

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com; 
    return 301 https://example.com$request_uri;
}
Bây giờ bạn có thể truy cập URL trang web của mình và kiểm tra xem nó có hoạt động hay không. Nếu nó không hoạt động, hãy làm theo các bước tiếp theo.

Force HTTPS for All Routes

Mở  app/Providers/AppServiceProvider.php và cập nhật boot() method:

use Illuminate\Support\Facades\URL;

public function boot()
{
    URL::forceScheme('https');
}

Bạn có thể thêm điều kiện

if (env('APP_ENV') === 'production') {
    URL::forceSchema('https');
}

if (env('APP_ENV') !== 'local') {
    URL::forceScheme('https');
}

if (env('APP_FORCE_HTTPS', false)) {
    URL::forceScheme('https');
}

Force HTTPS for Pagination Links

use Illuminate\Support\Facades\URL;

public function boot()
{
    if (env('APP_ENV') === 'production') {
        $this->app['request']->server->set('HTTPS','on'); // this line

        URL::forceSchema('https');
    }
}
Source: Force Laravel to Use HTTPS Connection for all Links
ShareShareSend
Theo dõi
Đăng nhập
Thông báo của
guest
guest
0 Góp ý
Phản hồi nội tuyến
Xem tất cả bình luận

Bài viết mới nhất

Validate hình ảnh base64 Laravel

[SEO Onpage] 200 yếu tố xếp hạng của Google: Onpage

Tất cả Shortcode WooCommerce

Google reCaptcha cho Laravel

VPS / Hosting nên dùng

  • Azdigi.com
  • Vietnix.vn

Liên kết

  • Tranhuuvan.com
  • Tienemall.com

Resource

  • Freepik.com
  • Flaticon.com
  • Unsplash.com

© 2022 Blog của Tiến - Hosted by AZDigi

No Result
View All Result
  • Laravel
  • WordPress
  • SEO
  • Đồ họa
  • Javascript
  • Download
  • Công cụ

© 2022 Blog của Tiến - Hosted by AZDigi

wpDiscuz
0
0
Rất thích suy nghĩ của bạn, hãy bình luận.x
()
x
| Trả lời