301几个(但不是全部)http到https

时间:2017-01-31 06:55:39

标签: .htaccess http redirect https

我有一个大约1.000个静态页面的网站,我想看看在移动整个网站之前,从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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

如果你在单独的RewriteRule语句中明确地想要它:

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]