.htaccess 301多个(但不是全部)http到https

.htaccess 301多个(但不是全部)http到https,.htaccess,http,redirect,https,.htaccess,Http,Redirect,Https,我有一个大约1000个静态页面的站点,我想看看在我移动整个站点之前,从http移动到https将如何影响50个页面的排名 我必须使用下面的第一个代码示例,还是第二个代码示例就足够了?还是有更好的方法 RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} ^/page-1.htm/?.*$ RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

我有一个大约1000个静态页面的站点,我想看看在我移动整个站点之前,从http移动到https将如何影响50个页面的排名

我必须使用下面的第一个代码示例,还是第二个代码示例就足够了?还是有更好的方法

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/page-1.htm/?.*$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/page-2.htm/?.*$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/page-3.htm/?.*$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


# OR IS THIS ENOUGH:


Redirect 301 /page-1.htm https://www.example.com/page-1.htm
Redirect 301 /page-2.htm https://www.example.com/page-2.htm
Redirect 301 /page-3.htm https://www.example.com/page-3.htm

您可以使用单个规则重定向此格式的多个页面page-n.htm

RewriteEngine on
RewriteCond %{HTTPS} off
 RewriteRule ^page-([0-9]+).htm$ https://%{HTTP_HOST}/page-$1.htm [NE,L,R=301]

如果明确希望将其包含在单独的重写规则语句中:

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteRule ^page-1\.htm$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

RewriteCond %{HTTPS} off
RewriteRule ^page-2\.htm$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

RewriteCond %{HTTPS} off
RewriteRule ^page-3\.htm$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

好的,谢谢。很高兴知道。如果文件名之间的差异大于此,您知道最好的方法是什么吗?假设它们是:blahblah.htm tjohoo.htm which.htm在这种情况下,您可以使用以下模式:^(+)\.htm$并将目标替换为https://%{HTTP\u HOST}/$1.htm问这个问题我感到非常尴尬,但您能给我这3个“虚拟”文件名的完整代码吗?第二个示例不起作用(除非您在单独的VirtualHost中有HTTPS,并且您仅将其应用于非HTTPS)。第一个示例是,您不需要在上使用第二个或第三个
重写引擎实例。starkeen的回答非常好