CodeIgniter (複数の開発者によって時間をかけてアップグレードされた古いバージョン) を使用する Web サイトがあります。サイトは HTTP を使用して 100% 正常に動作します (私のテスト環境では HTTPS を使用できません) が、HTTPS に切り替えるとすべての CSS 背景画像が IP アドレスの使用に切り替わりますか?
すべてのページに、使いやすいように次のスニペットを含めていますが、同じ IP アドレスを生成しているため、問題はsite_url()
関数にあると考えました -image_url()
に追加するだけsite_url()
です。
<script type="text/javascript">
var BASE_URL = '<?= site_url() ?>'; // http://555.555.55.555/
var IMG_PATH = '<?= image_url() ?>'; // http://555.555.55.555/images/main
</script>
変更をテストするための「ライブテスト環境」がなく、困惑しています。以下のオーバーライドされた関数force_ssl()
が問題を抱えている可能性があると思いますが、問題の原因や原因がわかりません。(force_ssl()
関数はhereから来ました。)
CodeIgnitercarabiner
プラグインを使用して CSS/JS を提供しており、次の関数を使用して SSL/HTTPS を強制していますmy_helper.php
。
if (!function_exists('force_ssl')) {
function force_ssl() {
if (ENVIRONMENT != 'development') {
$CI = & get_instance();
$CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']);
if ($_SERVER['SERVER_PORT'] != 443) {
redirect($CI->config->config['base_url'] . $CI->uri->uri_string());
}
}
}
}
/**
* Override the site_url function so it does https
*
* @param <type> $uri
* @return <type>
*/
function site_url($uri = '', $https = FALSE, $only_images_js_css = true) {
if ($https || (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443)) {
if (ENVIRONMENT != 'production') {
$secure_connection = FALSE;
} else {
$secure_connection = TRUE;
}
} else {
$secure_connection = FALSE;
}
$CI = & get_instance();
if (!$secure_connection) {
return str_replace("https://", "http://", $CI->config->site_url($uri));
} else {
// fallback - .htaccess should cover this - but just to make sure...
// If we only want the images, js, css, etc. to have https://
if ($only_images_js_css === true) {
$needs_ssl = false;
$extensions_to_check = array(".js", ".css", ".jpg", ".gif", ".png", ".ico");
foreach ($extensions_to_check as $extension_to_check) {
if (stristr($uri, $extension_to_check) !== FALSE) {
$needs_ssl = true;
break;
}
}
if ($needs_ssl === true) {
return str_replace("http://", "https://", $CI->config->site_url($uri));
} else {
return str_replace("https://", "http://", $CI->config->site_url($uri));
}
} else {
return str_replace("http://", "https://", $CI->config->site_url($uri));
}
}
}
これを行うより良い方法はありますか?(つまり、HTTP から HTTPS に切り替えます) および/site_url()
またはforce_ssl()
機能の何が問題になっていますか?