使用 .htaccess 强制使用 SSL 时出现问题

发布于 2024-10-05 14:35:55 字数 617 浏览 0 评论 0原文

我有以下 .htaccess 文件:

Order deny,allow
Deny from all
Allow from XX.XXX.XXX.XXX

RewriteEngine  on
RewriteBase    /

RewriteCond    %{REQUEST_FILENAME} !-f
RewriteCond    %{REQUEST_FILENAME} !-d
RewriteRule    . /index.php

RewriteCond    %{HTTPS} !=on
RewriteRule    ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

应该是:

  • 只允许从我的 IP 进行访问(数字更改为 X 以保护无辜者)
  • 将不是特定文件的任何请求发送到 /index.php
  • 对整个域强制使用 https

据我所知,它与之前的项目相同,诚然,该项目位于不同的托管提供商上,但这就像一个魅力。这次,它会显示一条消息:“Firefox 检测到服务器正在以永远不会完成的方式重定向对此地址的请求。”。

任何人都知道发生了什么事&请问我需要改变什么?

I have the following .htaccess file:

Order deny,allow
Deny from all
Allow from XX.XXX.XXX.XXX

RewriteEngine  on
RewriteBase    /

RewriteCond    %{REQUEST_FILENAME} !-f
RewriteCond    %{REQUEST_FILENAME} !-d
RewriteRule    . /index.php

RewriteCond    %{HTTPS} !=on
RewriteRule    ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

Which is supposed to:

  • Only allow access from my IP (numbers changed to Xs to protect the innocent)
  • Send any request which is not a specific file through to /index.php
  • Force https for the entire domain

As far as I can see, it's identical to a previous project, which was admittedly on a different hosting provider, but that worked like a charm. This time it's resulting in a message saying "Firefox has detected that the server is redirecting the request for this address in a way that will never complete.".

Anybody know what's going on & what I need to change please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最好是你 2024-10-12 14:35:55

也许您的新托管提供商正在使用某种设置(例如反向代理)来阻止设置 HTTPS 变量。您也许可以使用其他内容(例如 SERVER_PORT,或者远程代理设置的标头,假设有)来确定请求是 HTTPS 还是 HTTP。

Perhaps your new hosting provider is using some sort of setup (like a reverse proxy) that's preventing the HTTPS variable from being set. You may be able to use something else (like SERVER_PORT, or perhaps a header set by the remote proxy, assuming there is one) to determine if the request is HTTPS or HTTP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文