简单的 http(包括 www)到 https htaccess

Simple http (including www) to https htaccess

我想验证一下,如果我的重定向代码被实现了,那么在 seo 中不会有问题。 当前使用此代码:

我想这样做:

 - http://mydomain.tld to https://www.mydomain.tld
 - http://www.mydomain.tld to https://www.mydomain.tld

我目前的代码是:

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

目前正在重定向,不知道301实现的好不好?

如果您担心重定向是否会对有机排名产生负面影响,例如多个重定向(而不是一个干净的重定向),您可以使用此工具检查每个重定向 'hop':

RedirectDetective.com