.htaccess - 301 几个(但不是全部)http 到 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]

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]

关于.htaccess - 301 几个(但不是全部)http 到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41951391/

相关文章:

http - 发送复杂对象 GET 与 POST

php - 在友好 URL 的上下文中处理损坏的图像

.htaccess - modrewrite 页面的 htaccess 重定向

php - .htaccess 和错误页面 - 留在页面上,不要重定向

php - Laravel 应用程序不并行处理请求

c# - Owin:多次调用 OnApplyRedirect 并创建不正确的 RedirectUri

apache - htaccess 重写多个条件

python - 如何使用 python 的 urllib 设置标题?

html - 301 将用户重定向到 https 协议(protocol),但前提是用户使用的是 http 协议(protocol)

.htaccess - 具有排除条件的 301 重定向 (htaccess)