2011-04-21 62 views
0

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

回答

1

仔細查看我的Zend社區服務器的httpd.conf後,我意識到有兩個<Directory />指令。

<Directory "C:\Dropbox\www"> 
    # 
    # Possible values for the Options directive are "None", "All", 
    # or any combination of: 
    # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews 
    # 
    # Note that "MultiViews" must be named *explicitly* --- "Options All" 
    # doesn't give it to you. 
    # 
    # The Options directive is both complicated and important. Please see 
    # http://httpd.apache.org/docs/2.2/mod/core.html#options 
    # for more information. 
    # 
    Options Indexes FollowSymLinks 
    # 
    # AllowOverride controls what directives may be placed in .htaccess files. 
    # It can be "All", "None", or any combination of the keywords: 
    # Options FileInfo AuthConfig Limit 
    # 
    AllowOverride None 
    # 
    # Controls who can get stuff from this server. 
    # 
    Order allow,deny 
    Allow from all 
</Directory> 

我改變了下面一行AllowOverride None到的AllowOverride All`和它的工作:如圖所示的問題,第二個看起來像那個第一個是空的。對於那些想誰知道更多關於URL重寫使用CodeIgniter看看有:http://codeigniter.com/wiki/mod_rewrite/

而且要正確理解什麼AllowOverride不讀:http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride

再次感謝曾幫助過!

3

它會工作... ..actually你的前兩個重寫條件和規則工作,但在第三個條件改寫您允許用戶訪問請求文件,即使是核心或系統文件

RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !^core.* 
    RewriteCond %{REQUEST_FILENAME} !^system.* 
    RewriteRule ^(.*)$ index.php?/$1 [L] 

編輯:固定「改寫」錯字

+0

我仍然可以訪問核心文件夾,應用程序和sys夾被顯示。 – David 2011-04-21 19:08:20

0

ppet阻止用戶訪問應用程序文件夾 #提交者:Fabdrol #重命名'application'到您的應用程序文件夾名稱。 的RewriteCond%{REQUEST_URI} ^應用。* 重寫規則^(。*)$ /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]