【问题标题】:How to force a webpage to use HTTPs?如何强制网页使用 HTTPs?
【发布时间】:2015-02-27 09:20:45
【问题描述】:

我设计了一个在线购物网站。 http 一切正常。现在我希望配置文件和支付网关应该使用 HTTPS 而不是 HTTP。我以前没有处理过https,所以我被困在这里。这是我的代码 sn-p。我希望 profile.php 使用 https。我看过一些帖子,它被告知要编辑 mod_rewrite 或使用一些 https 重定向功能。但我将如何做到这一点?我正在使用 XAMPP。

    if($rws['user_email']==$UserName && $rws['user_pass']==$UserPwd){
        if($_REQUEST['remember']==1){
            setcookie('uname',$UserName,time()+24*60*60);
            setcookie('pwd',$UserPwd,time()+24*60*60);
        }

        $_SESSION['fname'] = $rws['user_fname'];
        $_SESSION['ud'] = $rws['user_id'];



        header('Location:profile.php');
       }

【问题讨论】:

标签: php .htaccess


【解决方案1】:

您需要在.htaccess 中添加一个重写条件

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

【讨论】:

  • 我不熟悉这个。你能解释一下如何编辑.htaccess吗?
  • 您需要重定向每个没有 https 的 url,在项目的根目录中创建一个 .htaccess 文件并通过代码。您只需要更改 url 地址。
  • 谢谢。我会试一试的。
猜你喜欢
  • 1970-01-01
  • 2013-11-12
  • 2020-06-03
  • 1970-01-01
  • 2018-05-09
  • 1970-01-01
  • 1970-01-01
  • 2011-11-23
  • 2015-04-01
相关资源
最近更新 更多