且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CodeIgniter重写URL:从URL中删除index.php

更新时间:2023-02-21 22:23:39

感谢/ * ActuallyMAB * /:您的代码确实有效。上面的代码在localhost(Windows上的WAMP Server)上有效。
如果您已将codeigniter项目放置在某个文件夹中,例如目录结构,则如下所示:

Thank /* ActuallyMAB */: Your code actually works. The above code works on localhost (WAMP Server on windows). If you have placed your codeigniter project in some folder such as your directory structure looks like:

C:\wamp\www\proposal

因此,您必须替换

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

RewriteRule ^(.*)$ /proposal{or your folder name}/index.php/$1 [L]

如果您的项目不是这种情况{您已经将您的codeigniter直接放入www文件夹},然后从上面的代码中删除了该文件夹的名称;

if this is not the case with your project {you have put your codeigniter directly into www folder}, then remove the folder name from the above code as it looks like;

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

也不要忘记更改

$config['index_page'] = 'index.php';

$config['index_page'] = '';

在配置文件夹{config.php}

in your config folder {config.php}

我希望其他人也提供相同的答案,但是由于上述代码在我的项目中有效,因此我也想提供一些详细信息。

I hope others have also provided the same answer, but since the above code works in my project and i felt to provide some details too.