【问题标题】:Codeigniter remove index.php on httpsCodeigniter 删除 https 上的 index.php
【发布时间】:2016-05-17 12:41:28
【问题描述】:

我使用 godaddy 作为我的服务器提供商,我购买了 SSL 证书。它让我对 CodeIgniter 项目中的 index.php 感到有些头疼。我无法从我的网址中删除 index.php。 我四处研究并尝试了我发现的所有东西,但对我没有任何作用,所以请不要将其视为双重。

如果:https://example.com/index.php/home - 工作得很好
如果:https://example.com/home
我收到 404 错误。未找到 在此服务器上未找到请求的文档。

到目前为止,我已经在我的 htaccess 文件中停止了这些条件:

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (sale|success|cancel) [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(static|sale|success|cancel) [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond $1 !^(index\.php|resources|robots\.txt|static) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

任何建议都会有所帮助。谢谢!

【问题讨论】:

  • 您是否也更改了$config['index_page'] = '';in application/config/config.php?
  • 你的 Apache 允许 mod_rewrite 吗?
  • 我在 godaddy 上使用 Windows 服务器,所以当我阅读时,他们不提供 mod_rewrite。所以我在我的.htaccess 文件中写了这个。 Options +FollowSymLinks Options +Indexes Options -MultiViews RewriteEngine On RewriteBase / 在文档中这几行,写得等了一个小时。我会看看会发生什么..

标签: .htaccess codeigniter ssl


【解决方案1】:

从 $config['base_url'] 中删除 index.php。

然后使用此链接从 url 中删除 index.php

http://addictors.in/remove-index-php-from-url-in-codeigniter/

然后重启服务器

【讨论】:

    【解决方案2】:

    我的最终结果:

    在助手中:

    //Force SSL injection
    if(!function_exists('force_ssl'))
    {
        function force_ssl() {
            if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") {
                $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
                redirect($url);
                exit;
            }
        }
    }
    

    在控制器中调用方法:force_ssl();

    .htaccess 中,index.php 是:

    DirectoryIndex index.php
    
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|robots\.txt)
    
    RewriteRule ^(.*)$ index.php?/$1 [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 2016-07-05
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 2012-10-30
      相关资源
      最近更新 更多