Reputation: 2540
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.
Upvotes: 1
Views: 108
Reputation: 785098
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]
Upvotes: 0
Reputation: 12391
With PHP
if (!preg_match("/https/i", $_SERVER['SERVER_PROTOCOL'])) {
header("Location: https://" .$_SERVER["SERVER_NAME"] ."/" . $_SERVER["REQUEST_URI"]);
die();
}
Upvotes: 1
Reputation: 4519
It should work,
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Upvotes: 0