【问题标题】:Force SSL in codeigniter在 codeigniter 中强制 SSL
【发布时间】:2012-07-14 01:28:19
【问题描述】:

我已经在网上搜索并尝试了大多数东西,最近几个小时但没有结果。

我使用了 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.sehttp://lotusmodellen.se

无论你写什么,不管有没有https,你都应该来www.lotusmodellen.se

但是好像有问题,重定向错误什么的。因为它不起作用。

有人有解决办法吗?

【问题讨论】:

    标签: .htaccess codeigniter ssl


    【解决方案1】:

    您好,只需在 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/';
    }
    

    【讨论】:

      猜你喜欢
      • 2012-07-13
      • 1970-01-01
      • 2019-04-12
      • 1970-01-01
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 2014-01-31
      • 2012-09-09
      相关资源
      最近更新 更多