.htaccess 重定向到 Drupal 7 站点上的 HTTP

.htaccess redirect to HTTP on Drupal 7 site

我在从 https 重定向到 http 时遇到问题。我这样做的原因是服务器有性能问题,因此在 Apache 之上有一个缓存服务器(侦听端口 80)。

所以为了减少负载,我想将所有没有cookie的请求(cookie只接受https)重定向到登录页面(/user)到http。

这是我的 .htaccess 文件,为了测试我删除了所有其他内容,没有进一步的重写规则。第三个 RewriteRule 来自 Drupal,将所有请求发送到 index.php.

<IfModule mod_rewrite.c>
  RewriteEngine on
  # Rewrite http to https for /user.
  RewriteCond %{HTTPS} !=on
  RewriteCond %{REQUEST_URI} =/user
  RewriteRule ^ https://%{HTTP_HOST}/user [R=301,L]
  #
  # Rewrite https to http for anonymous.
  RewriteCond %{HTTPS} =on
  RewriteCond %{HTTP_COOKIE} !SSESS
  RewriteCond %{REQUEST_URI} !=/user
  RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=307,L]
  #
  # Pass all requests not referring directly to files in the filesystem to
  # index.php. Clean URLs are handled in drupal_environment_initialize().
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]
</IfModule>

现在 /user 重定向到 https 工作正常。但随后 https://domain/user returns 以下响应 header (当没有 cookie 时):

Status: HTTP/1.1 307 Temporary Redirect
Location: http://domain/index.php

所以如果第二条规则失败,它想用 307 重定向到 /index.php? 有谁知道为什么会这样?

非常感谢, mpj

将第二条规则的 URI 条件更改为

RewriteCond %{THE_REQUEST} !\ /+user [NC]

您当前的规则也在重定向 index.php,在随后的重写周期中。