简体   繁体   English

如何在cPanel中不使用.htaccess文件的情况下强制HTTPS

[英]How to force HTTPS without using .htaccess file in cPanel

Recently I installed SSL. 最近,我安装了SSL。 It works fine , but my site doesn't redirect to https. 它工作正常,但是我的网站没有重定向到https。 My server isn't supporting htaccess file. 我的服务器不支持htaccess文件。 Is there any other way to do this?? 还有其他方法吗?

Thanks in advance. 提前致谢。

Try This trick once. 尝试一次此技巧。 I am not sure its going right way. 我不确定它是否正确。 Try it and let me know. 试试看,让我知道。

<?php

if ( $_SERVER['HTTPS'] == "" )
{
    header("HTTP/1.1 301 Moved Permanently");
    header('Location: https://yoursite.com.php');
}

?>

Now you can do your httpd.conf file or the file where your virtual host is specified and add these lines to redirect http to https: 现在,您可以执行您的httpd.conf文件或指定了虚拟主机的文件,并添加以下行以将http重定向到https:

<virtualhost *:80="">

ServerName mysite.com
ServerAlias www.mysite.com
Redirect / https://<your site name>/
DocumentRoot /var/www/public_html
</virtualhost>

你可以在if条件下使用

$_SERVER[REQUEST_SCHEME]!='https'

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

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