从代码点火器 URL 中删除索引.php


Remove index.php from codeigniter url

我是codeigniter的新手。我在我的代码点火器安装在本地主机/路径/learn_ci。

我已经遵循了代码点火器维基中给出的所有步骤。这是我的.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>

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

我收到此错误

"在此服务器上找不到请求的 URL/learn_ci/index.php/welcome"

我已经仔细检查了...Apache 中的mod_rewrite模块已打开。

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

正如其他人所说,请确保在您的 apache 配置或虚拟主机文件中将 AllowOverride 设置为 All。给定您设置代码点火器的路径,您的 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。

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

尝试:

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

您可以执行以下操作:

配置中的第一个.php文件集

$config['index_page'] = '';

接下来,在代码点火器根文件夹中创建一个 .htaccess 文件,并添加以下内容:

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

保存文件。它应该有效。

将 htaccess 文件放在根public_html文件夹中,与索引位于同一目录中.php

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

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

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

添加我的答案。我的项目基网址是http://localhost/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';

一切都开始起作用了。 现在没有索引.php文件。