.htaccess将http重写为https循环中的结果

在运行清漆的apache 2.2服务器上,我正在尝试将http – >redirect到整个Drupal Commons( http://commons.acquia.com/ )站点的https

由于清漆caching一些redirect(R = 301,但不是R = 302,我想),我首先得到了我的redirect工作:8080,这不是由清漆服务。

下面的.htaccess代码成功地将http:// foo.example.com:8080redirect到https:// foo.example.com。 (适用于Chrome,FF和Safari)

# RewriteBase / ### Standard Drupal7 .htaccess above here ### # SSL REWRITES RewriteCond %{SERVER_PORT} ^8080$ RewriteRule ^(.*)$ https://foo.example.com/$1 [NC,R=302,L] ### Standard Drupal7 .htaccess below here ### # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] </IfModule> 

如果我

  1. 将8080更改为80
  2. 保存.htaccess
  3. 重新开始清漆
  4. 清除Drupalcaching
  5. 清除浏览器caching
  6. 请访问http:// foo.example.com

(我在每次编辑.htaccess之后都虔诚地做了以上的工作)

当我访问http:// foo.example.com时,我在Chrome,FF,Safari中得到一个redirect循环。

为了理解循环,我改变了redirect,如下所示:

 # SSL REWRITES RewriteCond %{SERVER_PORT} ^80$ RewriteRule ^(.*)$ https://foo.example.com/$1/%{SERVER_PORT} [NC,R=302,L] 

我在地址栏中find了这个地址:https:// foo.example.com/80/80/80/80/80/80/80/80/80/80/80/80/80/80/80 / 80/80/80/80/80

当浏览器被转发到https url时,不应该SERVER_PORT = 443

更改为R = 301会导致相同的循环。

在同一个循环中testing%{HTTPS}结果。

 # SSL REWRITES #RewriteCond %{SERVER_PORT} ^80$ RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://foo.example.com/$1/%{HTTPS} [NC,R=301,L] 

现在我在我的位置栏中获取:https:// foo.example.com/off/off/off/off/off/off/off/off/off/off/off/off/off/off/off/off/off/off/off / OFF / OFF / OFF / OFF / OFF

每个http://drupal.org/node/181233#comment-278142 (和http://drupal.org/node/823232#comment-3075288 )我也试过:

 # SSL REWRITES RewriteCond %{SERVER_PORT} ^80$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ https://foo.example.com/$1/%{SERVER_PORT} [NC,R=301,L] 

尝试与没有! 否定-f和-d。 无论哪种方式,条件不匹配,所以什么也没有发生。 我不知道为什么这些-f,-dtesting将需要….

我也尝试删除RewriteRule中的正则expression式replace

 # SSL REWRITES RewriteCond %{SERVER_PORT} ^80$ RewriteRule ^.*$ https://foo.example.com/ [R=301,L] 

这仍然导致一个循环。

任何帮助将不胜感激。

我从服务器pipe理员那里发现他们在这个服务器上用Pound终止SSL。 这意味着SSL工作,但HTTP_SERVERvariables不反映我期望的值。 SERVER_PORT将始终为80,无论事情的真实状态如何,HTTPS将始终closures。

当使用mod_rewrite时,转储出你的服务器variables,看看你能用RewriteCondtesting什么。 请参阅http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html#PHP_Code_access_Apache_Variables

您也可以使用大多数编程语言将httpredirect到https。 我有Drupal的443session模块使用这个网站 – 它使用这种方法。 (即使无法检测到HTTPS已打开,我也不必告诉模块设置规则。)

确保你也使用安全的会话cookie。 除了mod_ssl之外,您还需要它们来防止会话劫持。

对于Drupal这是旧的,但很好http://drupalscout.com/knowledge-base/drupal-and-ssl-multiple-recipes-possible-solutions-https我认为drupal.org/project/443session是目前最好的模块选项&#x3002;