【发布时间】:2013-04-19 10:47:56
【问题描述】:
我在使用 Codeigniter2 时遇到了一些问题。 本质上,我想从我的网址中删除烦人的“index.php”,以便:
- http://localhost/ci_intro/index.php/site/home
Becomes
- http://localhost/ci_intro/home
我已经关注了 Stack Overflow 上的几个链接,并找到了以下两个帖子:
Remove index.php From URL - Codeigniter 2
和
Removing index.php from codeigniter-2
但是在执行完这两个步骤之后仍然没有乐趣。
我的.htaccess如下:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /ci_intro/index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /ci_intro/index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /ci_intro/index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
我已确保在 Apache 中启用了 mod_rewrite 模块(我在 Windows 上使用 Xampp),但由于某种原因,它并没有像我预期的那样工作。
我在 CodeIgniter2 中有两个视图,一个叫做 Home,另一个叫做 About。这两者是相互联系的。链接如下:
<a href="home">Home</a><br/>
<a href="about">About</a>
如果我转到我的项目的根 URL:
http://localhost/ci_intro/
首页的索引功能显示。这很好,正如预期的那样。但是,如果我然后单击其中一个链接,它会重定向到:
http://localhost/ci_intro/home
or
http://localhost/ci_intro/about
这会产生 404。但是,如果我随后在 URL 中键入“站点”,即我的控制器的名称,则链接会将我带到正确加载的视图:
http://localhost/ci_intro/site/home
or
http://localhost/ci_intro/site/about
是否有任何已知的方法绕过这种方法,以便控制器(在这种情况下为站点)从 URL 中完全删除,因为在我的视图中的链接中使用 site/home 或 site/about 似乎不起作用?
【问题讨论】:
标签: php .htaccess codeigniter mod-rewrite codeigniter-2