2013-02-20 23 views
0

我已经使用这个代码如何使用htaccess在某些页面上启用https也可以从Codeigniter中的URL中删除index.php?

Options +FollowSymLinks 
RewriteEngine on 

# redirect for http /buy page 
RewriteCond %{SERVER_PORT} =80 
RewriteRule ^buy/?$ https://mysite.com/buy [R=301,QSA,L,NE] 

# redirect for https non /buy pages 
RewriteCond %{SERVER_PORT} =443 
RewriteCond %{REQUEST_URI} !^/buy [NC] 
RewriteRule ^/?(.*)$ http://mysite.com/$1 [R=301,QSA,L,NE] 

这是工作的罚款HTTPS重定向,但我也想从我的URL.Here删除的index.php是该代码:

RewriteCond %{REQUEST_URI} ^/system.* 
RewriteRule ^(.*)$ index.php?/$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ index.php?/$1 [L] 

如何我可以加入这两个代码吗?请帮忙。

回答

2

你可以在代码中做到这一点。

创建帮助函数;像

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()); 
     } 
    } 
} 

然后只是在你想要的控制器的构造中调用这个函数。

E.g

public function __construct() { 
     parent::__construct(); 
     force_ssl(); 
} 
+0

感谢鲁尼:)它的工作... – Reetika 2013-02-20 11:22:11

+0

@Reetika这是伟大的。这是我与我一起狂欢的标准帮手功能之一。 – Rooneyl 2013-02-20 11:29:43

相关问题