2011-04-21 66 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]