7

我的目录结构是 /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 错误。谁能指导一下这条规则哪里错了?

4

7 回答 7

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
于 2013-01-13T08:22:48.277 回答
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 放在其自己的目录中,而是将 and 放在applicationsystem文件夹中。

于 2013-01-12T20:51:28.810 回答
3

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

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

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

让我知道它是否仍然无法正常工作。

于 2013-01-13T02:07:16.343 回答
1

使用以下步骤, 1. 在文档根目录 [ ]
中创建 .htaccess 文件。 2.打开配置文件,执行以下操作myroot_folder/.htaccess
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]
于 2013-12-07T17:03:54.467 回答
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().
于 2015-05-04T10:39:38.860 回答
0

1)制作.htaccess文件并放置此代码。

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

2) 改变:

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

3)从您的服务器重写

于 2018-01-29T10:01:43.143 回答
-1

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

在/etc/apache2/sites-available/default中的虚拟主机文件中将AllowOverride None更改为AllowOverride All

详情在这里

于 2015-04-10T22:11:41.377 回答