我在使用Zend Comunity Server和Apache的Windows机器上使用CodeIgniter。我的Apache配置正确处理的.htaccess指令和mod_rewrite的启用(httpd.conf文件):CodeIgniter删除index.php apache mod_rewrite
<Directory />
Options FollowSymLinks
AllowOverride FileInfo
Order deny,allow
Deny from all
</Directory>
我的根是C:\www\
和我的网站位于C:\www\david\
,当我键入http://localhost/david/
,在index.php被加载以及正确的控制器。我想直接通过http://localhost/david/Articles/
而不是http://localhost/david/index.php/Articles/
访问我的东西。要做到这一点,我必须使用Apache重写模块。
为此,我在C:\www\david\
文件夹中放置了一个.htaccess
文件。此文件包含的代码,我就发现here:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /david/
#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} ^core.*
RewriteRule ^(.*)$ /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 ^(.*)$ /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 ^(.*)$ 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>
我做了一些改动的代码,因为我的配置是从默认的有点不同。我不在根目录下,因此:'RewriteBase /davidfrancoeur.com/',我已将CodeIgniter系统文件夹重命名为额外的安全性: RewriteCond%{REQUEST_URI}^core。* RewriteRule ^(。*)$/index.php?/ $ 1 [L]
这样做,任何事情都应该正常工作,我应该能够访问http://localhost/david/Articles/
没有问题,我认为我不应该能够直接达到http://localhost/david/core/config/config.php
。
不幸的是,它不起作用,它甚至看起来没有任何重写。你看到我在这里做错了吗?有没有办法知道Apache是否真的重写任何东西?
非常感谢。是的,我看了几百万文章,我可以找到这个... :(
编辑
CI 2.0.2,PHP 5.3,Apache 2.2的
我仍然可以访问核心文件夹,应用程序和sys夹被显示。 – David 2011-04-21 19:08:20