0

ショッピングカートアプリにSSLルーティングソリューションを採用して、特定のページがhttps://ページとvisa-verseに「強制」されるようにしようとしています。調査を通じて、ヘルパー、フック、またはコントローラーのいずれかでコードを使用することを含む多くのソリューションに出くわしました。これらの解決策をいくつか試しましたが、それぞれでhttps://ページに切り替えるとリダイレクトエラーが発生します。

これが私が試した最後のバージョンです(ここにあります:http://nigel.mcbryde.com.au/2009/03/working-with-ssl-in-codeigniter):

ssl_helper.phpという名前のファイルをapplication/helperに作成します

if (!function_exists('force_ssl'))
{
    function force_ssl()
    {
        $CI =& get_instance();
        $CI->config->config['base_url'] =
                 str_replace('http://', 'https://',
                 $CI->config->config['base_url']);
        if ($_SERVER['SERVER_PORT'] != 443)
        {
            redirect($CI->uri->uri_string());
        }
    }
}

function remove_ssl()
{
    $CI =& get_instance();
    $CI->config->config['base_url'] =
                  str_replace('https://', 'http://',
                  $CI->config->config['base_url']);
    if ($_SERVER['SERVER_PORT'] != 80)
    {
        redirect($CI->uri->uri_string());
    }
}

ヘルパーをロードしてから、SSLを必要とするコントローラーのコンストラクターに次のように挿入します。

force_ssl();

sslを配置したくないすべてのコントローラーで:

if (function_exists('force_ssl')) remove_ssl();

上記のように、これを使用すると、リダイレクトループでスタックし、エラーが発生します(ただし、URLにはhttps://が含まれているはずです)。私の問題は私の.htaccessファイルにあるのでしょうか?これが私の.htaccessファイルです:

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /store
   RewriteCond $1 !^(index.php\.php|resources|robots\.txt)
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>

私はもう一週間以上これにいます!助言がありますか?

4

3 に答える 3

2

force_ssl関数を使用する場合のリダイレクトループの解決策は次のとおりです。

function check_ssl()
{
    $CI =& get_instance();
    $class = $CI->router->fetch_class();       
    $ssl = array('Register', 'SignIn', 'Recover');        
    if(in_array($class, $ssl))
    {
        force_ssl();
    }
    else
    {
        unforce_ssl();
    }
}
function force_ssl()
{        
    $CI =& get_instance();
    $CI->config->set_item('base_url', str_replace('http://', 'https://', config_item('base_url'))); 
    if ($_SERVER['SERVER_PORT'] != 443) // it will loop if you change it to !==
    {
        redirect($CI->uri->uri_string());
    }
}
function unforce_ssl()
{
    $CI =& get_instance();
    $CI->config->set_item('base_url', str_replace('https://', 'http://', config_item('base_url')));
    if ($_SERVER['SERVER_PORT'] != 80) // it will loop if you change it to !==
    {
        redirect($CI->uri->uri_string());
    }   
}
于 2013-09-11T15:06:27.703 に答える
1

私はここで同様の質問に答えました:https://stackoverflow.com/questions/1500527/how-to-use-ssl-with-codeigniter/1500558#1500558

しかし、一言で言えば:

<IfModule mod_rewrite.c>
   RewriteEngine On
   RedirectPermanent /sslfolder https://www.yoursite.com/sslfolder
</IfModule>
于 2012-07-13T22:15:43.200 に答える
0

こんにちはみんな、設定でbase_urlを設定して、ここで回答を確認してください。httpとhttpsが自動的に切り替わります。

ヘルパーなしでSSLを強制する

于 2012-07-15T06:25:30.343 に答える