【问题标题】:Removing index.php on CodeIgniter 2.2.0删除 CodeIgniter 2.2.0 上的 index.php
【发布时间】:2014-08-28 16:58:28
【问题描述】:

我在 Ubuntu 12.04.3(Windows 8.1 上的 Oracle VM)上运行 Apache 2.2.22。 使用 PHP phpinfo() 函数,我在 Loaded Modules 下的 apache2handler 部分看到 mod_rewrite,因此 mod_rewrite 已启用。

我对我的 CI 配置文件 (application/config/config.php) 进行了以下更改,

$config['index_page'] = 'index.php'; to: $config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; to: $config['uri_protocol']   = 'PATH_INFO';

我已经尝试了很多版本(.htaccess 文件位于 CI 的根目录):

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

但还没有让它工作。 我在这里还缺少什么?

【问题讨论】:

    标签: .htaccess mod-rewrite codeigniter-2


    【解决方案1】:

    成功了!

    RewriteEngine On
    RewriteBase /testsite/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    【讨论】:

    • 那么,我们必须在根目录下创建.htaccess 文件吗?我们知道.htaccess文件在codeigniter 2.2的根目录中不存在
    【解决方案2】:

    假设您的文件夹结构类似于... /var/www/html/testsite 并且您的 url 是 localhost/testsite,那么上面的重写规则将在 /var/www 中查找 index.php /html 而不是 /var/www/html/testsite。 ( /var/www/html 将是默认的文档根目录。)

    因此,在 /var/www/html/testsite 的等效文件夹中,您可以尝试在位于 /var/www/html/testsite/ 的 .htaccess 文件中使用以下内容。所以你会有 /var/www/html/testsite/.htaccess 的代码......

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

    我所做的只是删除了最后一行重写规则中的前导 /,因此它不会返回到默认文档根目录。

    【讨论】:

    • 感谢蒂姆的回复,但这没有用。我的 CI 设置在我的 VM 共享目录中,如下所示: Alias /testsite /media/sf_testsite/ Options -Indexes MultiViews AllowOverride None Order allow,deny Allow from all 跨度>
    猜你喜欢
    • 2012-09-30
    • 2016-07-05
    • 2016-05-17
    • 2011-07-09
    • 1970-01-01
    • 1970-01-01
    • 2012-10-30
    • 2011-10-28
    • 1970-01-01
    相关资源
    最近更新 更多