2013-02-20 44 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

相關問題