规范化所需的 .htaccess 文件帮助

.htcaccess file assistance needed for canonicalization

我的网站目前有两个版本 google,https://www.example.com and a https://example.com 这显然对 SEO 不利,因为它泄露了我所有的 seo 'juice'。我已经告诉 google 大约 5 周前只使用 www 版本,但 google 的结果仍然显示非 www 版本。我想知道是否有人可以帮助我的 .htaccess 获得重定向到 www.

htcaccess文件复制如下:

RewriteEngine on
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond  !^(blog)

RewriteCond %{HTTP_HOST} ^`.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.`.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/ [L]
RewriteRule ^(.+)$ /index.php [L]

对于简单的重定向,您可以使用:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

如果您还想强制使用 HTTPS:

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

注意:此块高于 www. 重写规则以确保这两个规则都有效