我已经在网上搜索并尝试了大多数事情,最近几个小时但没有结果。
我使用了 CodeIgniter,我有一个。 Htaccess 文件,其中我有一些规则。
我想强制 SSL 连接并从 url 中删除 index.php。
这是我的.Htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Force SSL
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#remove ugly index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Options All -Indexes
问题是它不起作用。我在 www.lotusmodellen.se 上安装了证书,所有流量都必须去那里。不是 lotusmodellen.se
请尝试进入这样的http://www.lotusmodellen.se或 http://lotusmodellen.se
无论你写什么,有或没有 https,你都应该来 www.lotusmodellen.se
不过好像是有问题,重定向错误什么的。因为它不起作用。
有没有人有解决办法?
最佳答案
您好,只需在 config.php 文件中替换您的 base_url,这将检查来自 https 或 http 的请求,将根据该请求设置您的 base_url。
if(isset($_SERVER['HTTP_HOST']))
{
$config['base_url'] = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
$config['base_url'] .= '://'. $_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
else
{
$config['base_url'] = 'http://localhost/';
}
关于.htaccess - 在 codeigniter 中强制使用 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11483312/