.htaccess 如何仅在使用htaccess的特定页面上启用https,同时从Codeigniter中的URL中删除index.php?
我用过这个代码.htaccess 如何仅在使用htaccess的特定页面上启用https,同时从Codeigniter中的URL中删除index.php?,.htaccess,codeigniter,.htaccess,Codeigniter,我用过这个代码 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 RewriteCon
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中删除index.php
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
我如何连接这两个代码。请帮助。您可以用代码完成 创建一个助手函数;差不多
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());
}
}
}
然后只需在所需控制器的构造中调用此函数
例如public function __construct() {
parent::__construct();
force_ssl();
}
@瑞蒂卡,太好了。这是我的一个标准助手函数,它让我非常兴奋。