我已经搜索了网络,现在尝试了大部分事情,最近几个小时却没有结果。
我使用CodeIgniter而且我有一个。 Htaccess文件,我有一些规则。
我想强制使用SSL连接并从网址中删除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
但它似乎是问题,重定向错误或其他什么。因为它不起作用。
有没有人有解决方案?
答案 0 :(得分:0)
您只需在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/';
}