2017-09-27 84 views
0

我工作的一个预先存在的笨(v2.1.4)应用程序中添加HTTPS/SSL它。笨2.x的SSL重定向循环

我在webfaction托管工作。他们的ssl设置的常规方法包括在主机仪表板中添加第二个网站记录,该记录使用.htaccess将http://重定向到https://(为清楚起见,我们将其称为.htaccess_B)文件。本网站只记录包含此.htaccess文件:

RewriteEngine On 
RewriteCond %{HTTP:X-Forwarded-SSL} !on 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

其中包含的CodeIgniter应用程序的原始网站记录包含这个的.htaccess(.h​​taccess_A)文件

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php|javascript|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

的SSL证书已正确安装和配置根据网站主机说明。我试过this方法(顶部的答案),但我卡在重定向循环。在config.php

我的配置变量:

$config['base_url'] = ''; 
$config['enable_hooks'] = TRUE; 
$config['cookie_secure'] = TRUE; 

hooks.php

$hook['post_controller_constructor'][] = array(
    'function' => 'redirect_ssl', 
    'filename' => 'ssl.php', 
    'filepath' => 'hooks' 
    ); 

和我ssl.php

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 
function redirect_ssl() { 
    $CI =& get_instance(); 
    $class = $CI->router->fetch_class(); 
    $exclude = array(''); // add more controller name to exclude ssl. 
    if(!in_array($class,$exclude)) { 
     // redirecting to ssl. 
     $CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']); 
     if ($_SERVER['SERVER_PORT'] != 443) redirect($CI->uri->uri_string()); 
    } else { 
     // redirecting with no ssl. 
     $CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']); 
     if ($_SERVER['SERVER_PORT'] == 443) redirect($CI->uri->uri_string()); 
    } 
} 

`

我试着几个东西,包括重命名.h taccess文件放在原始网站记录(.htaccess_A)上,用https://添加base_url无效。我一直陷在一个重定向循环

GET https://mydomainhere.com/网:: ERR_TOO_MANY_REDIRECTS铬 控制台

任何想法?

感谢

+0

尝试开出罚单与他们。我不熟悉PHP,但是我上周在webfaction做了一个django站点的重定向。同样的方法.htaccess文件。他们检查并认为这是由于我的浏览器缓存。我清除缓存后,它工作。他们相当有帮助。 – ionescu77

回答

0
  1. 变化BASE_URL在你的配置:

    $config['base_url'] = 'https://mydomainhere.com/'; 
    
  2. 重定向的传入流量从http到https:

    RewriteCond %{HTTPS} off 
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]