简体   繁体   中英

301 several (but not all) http to https

I have a site of about 1.000 static pages, and I would like to see how moving from http to https will effect ranking for, say, 50 pages before I move the entire site.

Do I have to use the first code example below or is it enough with the second one? Or is there a better way to do it?

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

You can use a single rule to redirect multiple pages of this format page-n.htm

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

If you explicitly want it in separate RewriteRule statements:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM