1

目前,服务器将任何 HTTP 请求重定向到http://www.example.com/index.php到 HTTPS。

RewriteEngine on

RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} index.php$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

但是,问题是当向http://www.example.com发出请求时,没有进行重定向。

在 {REQUEST_URI} 为空的情况下,如何使服务器重定向到 HTTPS。(我假设它是空的)

编辑:
在 akostadinov 的回答之后,我修改了 .htaccess 以包含它,并且重写工作。我会在这里发布,以防以后有人遇到同样的问题!

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

1 回答 1

0

请求是/。请参阅curl -v下面的输出(截断)。顺便说一句,如果您真的不需要匹配特定条件,则可以省略 URI 条件。

$ curl -v example.com
* About to connect() to example.com port 80 (#0)
*   Trying 192.0.43.10...
* connected
* Connected to example.com (192.0.43.10) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.27.0
> Host: example.com
> Accept: */*
...
于 2013-02-19T09:36:52.157 回答