我在使用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