从codeigniter url中删除index.php

时间:2012-06-12 07:46:58

标签: php .htaccess codeigniter

我是codeigniter的新手。我的codeigniter安装在localhost / path / learn_ci。

我已经遵循了codeigniter wiki中给出的所有步骤。这是我的.htaccess文件。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /learn_ci/index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

我还根据需要更改了配置文件。但是当我试图访问时     

我收到此错误

  

“在此服务器上找不到请求的网址/learn_ci/index.php/welcome”

我已仔细检查过...... Apache中的mod_rewrite模块已启用。

RewriteBase解决方案也不起作用。我做错了吗?

6 个答案:

答案 0 :(得分:2)

正如其他人所说,请确保在apache配置或虚拟主机文件中将AllowOverride设置为All。 鉴于您已设置codeigniter的路径,您的htaccess应如下所示:

RewriteEngine On
RewriteBase /path/learn_ci

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /path/learn_ci/index.php/$1 [L]

此外,请记住,您使用的任何资产(img,css,js等)都可以使用base_url()函数或使用相对路径引用。项目的根目录是/ path / learn_ci。

我发现创建虚拟主机并在本地向主机文件添加条目更容易。这样可以更好地模仿现实生活。

答案 1 :(得分:1)

尝试:

RewriteEngine On
RewriteBase /

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

答案 2 :(得分:1)

您可以执行以下操作:

首先在config.php文件集中

$config['index_page'] = '';

接下来,在codeigniter根文件夹中创建一个.htaccess文件,并添加以下内容:

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

保存文件。它应该工作。

答案 3 :(得分:0)

将htaccess文件放在root public_html文件夹中与index.php相同的目录中

然后从你的htaccess文件中删除/ learn_ci,只需将其设为/index.php/$1

答案 4 :(得分:0)

检查你的apache配置,它应该是这样的:

Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all

答案 5 :(得分:0)

我想加上我的回答。我的项目基础网址为http://localhost/newproject/ 我在newproject文件夹中包含了htacess文件。

这是代码。

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L,QSA]

然后我更改配置文件。

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

并且每件事都开始起作用了。现在nomore index.php文件。

相关问题