【问题标题】:CodeIgniter's "Removing the index.php file" is not working when CI is inside a subfolder当 CI 在子文件夹中时,CodeIgniter 的“删除 index.php 文件”不起作用
【发布时间】:2013-07-28 22:59:52
【问题描述】:

当我编辑 .htaccess 以从我的 url 中删除 index.php 时,我正在使用 CI 2.1.4(尝试使用)它不起作用。我的项目在一个子文件夹中:

http://myserver.dev/project/

我已设置 base_url 从 $config['index_page'] = '' 中删除了 index.php 并粘贴了确切的代码形式 http://ellislab.com/codeigniter/user-guide/general/urls.html:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

尝试了一些来自 stackoverflow.com 研究员的解决方案(一些使用 RewriteBase),但是它不起作用。 我该如何解决?

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting codeigniter-2


    【解决方案1】:

    我不认为这是因为 .htaccess,这对我有用,也不是因为子文件夹。

    这是我正在使用的 .htaccess 示例:

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

    在 base_url 或 this 中设置正确的 url:

    $config['base_url']     = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '')
                      .'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/');
    

    显然:

    $config['index_page'] = '';
    

    有了这个,它对我有用......

    【讨论】:

    • 非常感谢,但也没有用。仍然收到“错误 404”。即使使用最近提取的 CI 2.1.4。
    • /etc/httpd/conf/httpd.conf 中的 Apache 配置 AllowOverride 出于某种原因被设置为 None。永远不会加载 .htaccess 配置。一个鬼魂,或者我自己(不在我的脑海里)改变了它。 :) 非常感谢!
    • @tenshimsm 请告知您的 httpd.conf 文件中发生了什么变化,以便其他人可以看到。
    猜你喜欢
    • 2017-01-19
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-22
    • 2014-08-12
    相关资源
    最近更新 更多