htaccess - 将单个 HTML 页面重定向到 HTTPS

htaccess - redirect single html page to https

本文关键字:重定向 HTTPS HTML 单个 htaccess      更新时间:2023-09-26

我需要将单个html页面重定向到https。为此,我也尝试 https://stackoverflow.com/questions/16152914/redirect-single-page-http-to-https 这个。但它不起作用。

我的网址格式是http://www.example.com/api/test.html,我需要将此测试.html页面转换为https://www.example.com/api/test.html

请提供任何帮助。

使用 PHP

if (!preg_match("/https/i", $_SERVER['SERVER_PROTOCOL'])) {
    header("Location: https://" .$_SERVER["SERVER_NAME"] ."/" . $_SERVER["REQUEST_URI"]);
    die();
}

它应该可以工作,

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

您可以使用:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} 's/+api/test'.html['s?] [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]