手动输入完整网址时网站不安全? [复制]

Posted

技术标签:

【中文标题】手动输入完整网址时网站不安全? [复制]【英文标题】:Website is not secured when full url is entered manually? [duplicate] 【发布时间】:2021-08-18 02:59:20 【问题描述】:

我在 myapp.com 上有一个安装了 SSL 证书的 React 应用程序。 当我在浏览器中输入 myapp.com 时,它会按预期转到https://myapp.com。如果我从那里导航到 /shop,它仍然是安全的。

但问题是当我在 url 中手动输入 myapp.com/shop 时。那么连接就不安全了。

这是我的 .htaccess 文件:

RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteCond %REQUEST_FILENAME !-l
RewriteRule . /index.html [L]

RewriteCond %HTTPS !on
RewriteRule (.*) https://%HTTP_HOST%REQUEST_URI

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

【问题讨论】:

【参考方案1】:

您缺少重写规则 [R,L] 的标志

完整代码:

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

另一个最佳做法是使用端口检查更改 HTTPS 检查,但这是可选的,因为您的代码也应该可以正常工作。

RewriteCond %SERVER_PORT 80
RewriteRule (.*) https://%HTTP_HOST%REQUEST_URI [R,L]

【讨论】:

以上是关于手动输入完整网址时网站不安全? [复制]的主要内容,如果未能解决你的问题,请参考以下文章