繁体   English   中英

仅在特定页面上使用HTTPS-Htaccess,Apache,OpenSSL

[英]HTTPS only on specific pages - Htaccess, Apache, OpenSSL

我正在尝试使HTTPS能够按我的意愿工作,但是没有运气。 我想做的是让网站浏览http和特定网址上的https。 具体的网址是:reg.php和glomtpass.php。

但是,当我尝试该代码时,它显示:“此网页具有重定向循环”。 经过一堆尝试后,它仍然存在该错误。

我现在在.htacess中使用的HTTP-> HTTPS代码:

RewriteCond %{HTTPS} on
RewriteCond %{SCRIPT_FILENAME} !\/(reg|glomtpass)\.php [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

任何帮助表示赞赏!

如果在页面顶部添加功能文件不是很麻烦,那么这就是我检查在php中移入和移出HTTPS的方式。 要使用它,只需将文件放入所有脚本中即可。

功能文件

<?php

$scriptsWithSSL = array('reg.php','glomtpass.php');
if (in_array(end(explode('/', $_SERVER['PHP_SELF'])), $scriptsWithSSL) === true) {
    //we are on a page we want to be HTTPS. will become HTTPS if requested with HTTP
    if ($_SERVER['HTTPS'] == '' || $_SERVER['HTTPS'] == 'off') {
        header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $_SERVER['QUERY_STRING']);
        exit;
    }
} else {
    //page should not be HTTPS and will move to HTTP if requested with HTTPS
    if (strtolower($_SERVER['HTTPS']) == 'on') {
        header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $_SERVER['QUERY_STRING']);
        exit;
    }
}
?>

这将是在$scriptsWithSSL数组中找到的任何脚本,如果未通过HTTPS请求将其移至HTTPS。 否则,其为正常页面,如果未通过HTTP请求,则将从HTTPS移至HTTP。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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