无法从CodeIgniter URL中删除index.php

时间:2013-01-12 20:43:46

标签: .htaccess codeigniter codeigniter-2

我的目录结构是/ var / www / CI /,文件夹CI下有所有文件夹,即应用程序,系统。在CI下创建了一个.htaccess文件。

以下是.htacess中的代码。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

仍然localhost / CI / blog出现404错误。任何人都可以指导这条规则的错误吗?

7 个答案:

答案 0 :(得分:26)

请尝试以下

首先,请确保将配置文件设置为以下内容..

$config['index_page'] = '';

还要确保在httpd.conf文件中启用 mod_rewrite ,然后使用以下代码覆盖位于项目根文件夹中的.htaccess文件,而不是在应用程序文件夹中。

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

答案 1 :(得分:3)

确保在application/config/config.php文件中设置如下:

$config['index_page'] = '';

也这样做:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^CI/(index\.php|public|images|robots\.txt|css)
    RewriteRule ^CI/(.*)$ CI/index.php/$1 [L]
</IfModule>

通常,您不会将CI放在自己的目录中,并将applicationsystem放在根文件夹中。

答案 2 :(得分:3)

检查您的Apache配置,以便允许覆盖。 如果AllowOverride设置为None,则重写将不适合您。

将以下内容添加到httpd.conf(不是您的.htaccess)可以解决您的问题

<Directory "/">
    AllowOverride All
</Directory>

请告诉我它是否仍无效。

答案 3 :(得分:1)

使用以下步骤,
1.在文档根[myroot_folder/.htaccess]中创建.htaccess文件。
2.在application/config/config.php中打开配置文件并执行以下操作

$config['index_page'] = '';

从基本网址中删除index.php 如果是$config['base_url']= 'http://localhost/myroot_folder/index.php';
将其更改为$config['base_url']= 'http://localhost/myroot_folder/';

现在打开.htaccess文件并添加以下代码块

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

答案 4 :(得分:1)

这很有效。不过,请确保您的 mod_rewrite 已启用,

  1. 在Apache安装文件夹中的httpd.conf文件夹下找到C:\wamp\bin\apache\apache2.4.9\conf文件。
  2. #LoadModule rewrite_module modules/mod_rewrite.so文件中找到以下行httpd.conf。您可以通过搜索关键字“mod_rewrite”轻松完成此操作。
  3. 删除行首的##表示该行已注释。
  4. 然后重新启动apache服务器
  5. 执行mod_rewrite时,您现在可以在“已加载模块”部分中看到phpinfo()

答案 5 :(得分:0)

1) make .htaccess file and put this code

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

2) change

 $config['index_page'] = ''; 
 remove index.php present in config.php file

3) rewrite on from your server

答案 6 :(得分:-1)

如果您没有完成所有操作,请尝试以下操作:

/ etc / apache2 / sites-available / default

中的 AllowOverride无更改为虚拟主机文件中的 AllowOverride All

Details here

相关问题