将 301 站点所有网址 www 重定向到 htaccess 中带有 https 的非 www

问题描述 投票:0回答:1

我无法将所有网站页面从

www
重定向到
non-www
https

我用

Laravel 11

我尝试了这个,但这仅适用于我的主页:

RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
laravel .htaccess
1个回答
0
投票

试试这个:

<IfModule mod_rewrite.c>
RewriteEngine On

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

# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

# Laravel standard rules follow
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
© www.soinside.com 2019 - 2024. All rights reserved.