【问题标题】:remove index.php file in CI ubuntu 12.04删除 CI ubuntu 12.04 中的 index.php 文件
【发布时间】:2013-03-22 07:07:01
【问题描述】:

我想从 CI 的文件路径中删除 index.php 文件。我正在使用 ubuntu 12.04 。我尝试了几乎所有的论坛结果,但没有成功。

我将 CI 文件夹放在此路径。

http://localhost/xxx/CI/

我有 apache rewrite mod enable 。

sudo a2enmod rewrite
Module rewrite already enabled

我的 conf.php 文件中也有这个

$config['uri_protocol'] = 'AUTO';
$config['base_url'] = 'http://localhost/xxx/CI/'; 
$config['index_page'] = '';
$config['index_url'] = '';

我的 .htaccess 文件中有这个

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

.htaccess 文件位于此路径

http://localhost/xxx/CI/.htaccess

它也可以通过 apache 启用

/etc/apache2/sites-available/default
AllowOverride All

当我访问这样的文件时出现此错误

 http://localhost/xxx/CI/login/
 404 Error
 The requested URL /xxx/CI/login/ was not found on this server.

任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 您是否收到 404 错误?你的.htaccess 文件在哪里?
  • 是的,麦克我得到 404 错误。我的 .htaccess 文件位于此路径 localhost/xxx/CI/.htaccess

标签: php .htaccess codeigniter mod-rewrite


【解决方案1】:

尝试使用下面的.htaccess 文件:

RewriteEngine On
RewriteBase /xxx/CI/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]

然后,将您的 uri_protocol 从 AUTO 更改为 PATH_INFO:

$config['uri_protocol'] = 'PATH_INFO';

如果开始将所有内容重新路由到默认控制器,则将其更改为 ORIG_PATH_INFO:

$config['uri_protocol'] = 'ORIG_PATH_INFO';

其他信息

将这些行插入到您的文件中:

Options -Multiviews +FollowSymLinks
AllowOverride All

【讨论】:

  • 非常感谢您的回复,我完全按照您所说的做了,但仍然无法正常工作并给我 404 错误。首先,我将 uri_protocol 更改为 PATH_INFO,它显示 404 错误,而不是我将其更改为 ORIG_PATH_INFO 它再次显示 404 错误:(
  • 我在这个文件的前面有这个 /etc/apache2/sites-available/default Options Indexes MultiViews FollowSymLinks AllowOverride All 我根据你的消息更改为这个仍然 404 错误,我也重新启动了 apache。
  • 这是一个实际的配置文件吗?您是否尝试将其放入httpd.conf 文件中?
  • 现在 404 错误已被删除,但无论我访问什么页面,它都只显示相同的视图。
  • +1 我认为问题出在选项上。好的。 URI 路径不应该像问题中那样传递给index.php 吗?
【解决方案2】:

试试下面:

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

并检查必须启用apache的“rewrite_module”。

并且你的配置中的 index_page 应该是空白的 $config['index_page'] = '';

【讨论】:

  • 我试过了,但没用,是的,apache rewrite_module 也已启用,这也是真的 $config['index.php'] ='';
  • 我把这个放到 RewriteBase /var/www/xxx/CI/
  • 我把 RewriteBase 改成了这个 xxx/CI/ 但还是同样的问题,我什至重启了 apache。
  • 我试过了,但没有运气,我逐行尝试了两行但没有任何反应 RewriteRule ^(.*)$ /var/www/xxx/CI/index.php/$1 [L]/重写规则 ^(.*)$ /xxx/CI/index.php/$1 [L]
【解决方案3】:

你的 htaccess 文件中有这段代码吗

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

【讨论】:

    猜你喜欢
    • 2015-05-22
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    相关资源
    最近更新 更多