简体   繁体   中英

htaccess - redirect single html page to https

I need to redirect single html page to https. For this I've tried https://stackoverflow.com/questions/16152914/redirect-single-page-http-to-https this also. but it's not working.

my web url format is http://www.example.com/api/test.html , I need to convert this test.html page to https://www.example.com/api/test.html

any help please.

With PHP

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

It should work,

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

You can use:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} \s/+api/test\.html[\s?] [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,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