【问题标题】:http to https redirection not working while accessing admin area which pretected by htpassword访问受 htpasswd 保护的管理区域时,http 到 https 重定向不起作用
【发布时间】:2019-06-28 15:03:09
【问题描述】:

我使用下面的代码从 http 重定向到 https 和 www 到非 www。

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

在管理目录中,我使用下面的代码来密码保护管理目录。

AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /path/public_html/admin/.htpasswd
Require valid-user

使用 https 模式访问管理员时,如下所示

https:://example.com/admin

它工作正常,但在使用 http 模式访问而不是将其重定向到错误页面时

http:://example.com/admin

谢谢。

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    最后我从下面的 StackOveflow 问题中得到了我的问题的答案

    Do HTTP authentication over HTTPS with URL rewriting

    我缺少以下两件事。

     SSLRequireSSL
     ErrorDocument 403 https://www.example.com/secure-page.php
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2018-10-25
      • 2014-03-10
      • 2018-06-11
      • 2015-07-28
      • 2022-01-14
      • 2021-04-15
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多