2013-01-12 73 views
7

我的目录结构是/ var/www/CI /包含文件夹CI下的所有文件夹,即应用程序,系统。在CI下创建了一个.htaccess文件。无法从CodeIgniter网址中删除index.php

以下是.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 /博客给404错误。任何人都可以指导这个规则错误的地方吗?

回答

26

请尝试以下

首先,请确保您设置的配置文件,如下面..

$config['index_page'] = ''; 

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

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

它对我来说就像一个魅力!谢谢! – JunaidKirkire

+0

你是最受欢迎的 –

+0

我已经扔了几个博客和帖子寻找这个答案,你是唯一一个对我有正确答案,并且在做什么时非常清楚。非常感谢! –

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在根文件夹中。

+0

做了以上,但仍然无法正常工作。还有其他地方还需要配置吗? – JunaidKirkire

+0

谢谢神秘的建议。我很感激。 – JunaidKirkire

3

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

添加以下到您httpd.conf(不是你的.htaccess)应该解决您的问题

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

让我知道,如果它仍然没有工作。

+0

请纠正我,如果我错了,但不应该是httpd.conf?我的httpd.conf文件也是空的。 – JunaidKirkire

+0

感谢您花时间回答我的问题。我很感激。 – JunaidKirkire

+0

对不起,我的错误...它是httpd.conf!我确定了我的答案。我希望这个解决方案有帮助 – ashiina

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] 
-1

如果你没有工作了,但你这样做了,试试这个:

变化的AllowOverride无的AllowOverride在的/ etc/apache2的/网站可用/默认虚拟主机文件中的所有

Details here

1

这工作。虽然,请确保您的的mod_rewrite启用,

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