我正在使用 Codeigniter 并关注 these instructions强制 ssl 但所有请求都被重定向到
http://staging.example.com/index.php/https:/staging.example.com
我的 .htaccess
是:
### Canonicalize codeigniter URLs
# Enforce SSL https://www.
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
###
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
最佳答案
您可以在代码中完成,而不是使用 htaccess。
您可以创建一个辅助函数,将页面重定向到 SSL,您可以从 Controller 调用它。
在你的助手中;
function force_ssl() {
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") {
$url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
redirect($url);
exit;
}
}
然后在你的 Controller 中;
class Whatever extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper(array('your_ssl_helper'));
}
public function index() {
force_ssl();
...
}
}
关于php - 使用 mod_rewrite 在 htaccess 中为 Codeigniter 强制使用 https ://www.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8503663/