【发布时间】:2011-08-10 12:46:41
【问题描述】:
我在使用 Zend 社区服务器和 apache 的 Windows 机器上使用 CodeIgniter。我的 apache 已正确配置为处理 .htaccess 指令,并且启用了 mod_rewrite (httpd.conf):
<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
【问题讨论】:
标签: apache codeigniter mod-rewrite