2017-09-27 49 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]