怎样才可以有使用SSL笨负载特定的网页? 我有一个的Apache2 / mode_ssl
服务器。 mod_ssl
使用不同的文档根比非安全网页。 例如,HTTPS(端口443)将发球出的页面/var/www/ssl_html/
和HTTP(80端口)提供了页面/var/www/html/
。 我怎么会得到笨发挥好与此设置?
Answer 1:
有解决这个几个方法。
选项1:
我可能会部署到这两个文件夹的代码,然后在文件:/system/application/config/config.php,设定你的网页:
$config['base_url'] = "http://www.yoursite.com/";
要么
$config['base_url'] = "https://www.yoursite.com/";
然后在您的非SSL虚拟主机文件夹,设置你的配置重定向保护的页面被夹到SSL网站:
RedirectPermanent /sslfolder https://www.yoursite.com/sslfolder
选项2:
发送一切SSL,并保持所有的代码在一个文件夹中
/system/application/config/config.php,设定你的网页:
$config['base_url'] = "https://www.yoursite.com/";
其他选项
还有一些更哈克的方式与头要做到这一点()重定向等,但我不认为你想保持这个选项不同的代码库。 我不建议这样做,但你可以这样做:
$config['base_url'] = “http://” . $_SERVER['http_host'] . “/”;
Answer 2:
在应用程序/配置/ config.php文件,BASE_URL设置为:
$config['base_url'] = ($_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http') . "://{$_SERVER['HTTP_HOST']}/";
这将允许它在任何领域,如果你在本地测试是方便工作。
Answer 3:
我把下面的行./application/config/config.php文件,并将其完美的作品:
$protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http';
$config['base_url'] = $protocol.'://www.yoursite.com';
Answer 4:
我会保持两套代码,并办理强制重定向到HTTPS页面与post_controller_constructor挂钩。 之前每个页面呈现,以检查是否访问者应根据您网站上的当前位置被重定向到HTTPS挂钩将被调用。
步骤1
创建文件:系统/应用/钩/ SecureAccount.php
<?php
class SecureAccount
{
var $obj;
//--------------------------------------------------
//SecureAccount constructor
function SecureAccount()
{
$this->obj =& get_instance();
}
//--------------------------------------------------
//Redirect to https if in the account area without it
function index()
{
if(empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] !== 'on')
{
$this->obj =& get_instance();
$this->obj->load->helper(array('url', 'http'));
$current = current_url();
$current = parse_url($current);
if((stripos($current['path'], "/account/") !== false))
{
$current['scheme'] = 'https';
redirect(http_build_url('', $current), 'refresh');
}
}
}
}
?>
第2步
自定义在其网站的区域应该被强制使用HTTPS功能的路径。
STEP 3
以下内容添加到系统/应用/配置/ hooks.php
/* Force HTTPS for account area */
$hook['post_controller_constructor'] = array(
'class' => 'SecureAccount',
'function' => 'index',
'filename' => 'SecureAccount.php',
'filepath' => 'hooks',
'params' => array()
);
Answer 5:
我可以很容易,我只定义:
$config['base_url'] = '';
CI得到BASE_URL automaticaly = d
Answer 6:
我解决了这个问题,在config.php
$config['ssl_active'] = false;
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) {
$config['ssl_active'] = true;
}
$config['base_url'] = ($config['ssl_active'] === true )?"https":"http" . $_SERVER['HTTP_HOST'];
该目录的麻烦,你可以使用一个简单simbolic链接LN -s
Answer 7:
这是对我工作。 我们的服务器都具有$ _ SERVER [ 'SERVER_PORT']和$ _ SERVER [ 'HTTP_X_FORWARDED_PORT']
我们应该先检查是否$ _ SERVER [“HTTP_X_FORWARDED_PORT”]可用,并且用这个来代替$ _ SERVER [“SERVER_PORT”]
$config['base_url'] =
( ( ( empty($_SERVER['HTTP_X_FORWARDED_PORT']) ? $_SERVER['SERVER_PORT'] : $_SERVER['HTTP_X_FORWARDED_PORT'] ) == 443 ? 'https' : 'http') . "://" . $_SERVER['HTTP_HOST'] )
. str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']) ;
这个测试我们的Linux服务器上...
顺便说一句,它是基于其是之前斯凯勒的答案。
$config['base_url'] = ($_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http') . "://{$_SERVER['HTTP_HOST']}/";
Answer 8:
即来到我的脑海解决方案是使用str_replace()函数像这样
$base_url_str = base_url();
$secure_base_url = str_replace("http","https",$base_url_str );
每当我需要一个安全的地方,我用$ secure_base_url代替BASE_URL(),所以我们说,你BASE_URL()是http://www.example.com然后$ secure_base_url将https://www.example.com
Answer 9:
另一个问题是与此类似
您可以使用相对协议网址 ,这将持续保持在连接在CI。
在你config.php
而不是:
$config['base_url'] = 'http://example.com/';
放;
$config['base_url'] = '//example.com/';
有关协议相链接的信息在这里 。
Answer 10:
这里有一个很好的解决方案。 http://sajjadhossain.com/2008/10/27/ssl-https-urls-and-codeigniter/