CodeIgniter删除index.php apache mod_rewrite [英] CodeIgniter remove index.php apache mod_rewrite

查看:79
本文介绍了CodeIgniter删除index.php apache mod_rewrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows计算机上使用CodeIgniter,该计算机将Zend Comunity Server与apache一起使用.我的apache已正确配置为处理.htaccess指令并启用了mod_rewrite(httpd.conf):

I'm using CodeIgniter on a Windows machine using the Zend Comunity Server with apache. My apache is properly configured to handle .htaccess directives and mod_rewrite is enabled (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重写模块.

My root is C:\www\ and my site is located in C:\www\david\ and when I type http://localhost/david/, the index.php is loaded along with the correct controller. I want to access my things directly through http://localhost/david/Articles/ instead of http://localhost/david/index.php/Articles/. To do this I have to use apache rewrite module.

为此,我将.htaccess文件放置在C:\www\david\文件夹中.该文件包含我在此处

To do so, I've placed a .htaccessfile in the C:\www\david\ folder. This file contains code I found on 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> 

我对代码进行了一些更改,因为我的配置与默认配置有所不同.我不在root上,所以:'RewriteBase/davidfrancoeur.com/',并且我已将CodeIgniter系统文件夹重命名以提高安全性,因此: RewriteCond%{REQUEST_URI} ^核心.* RewriteRule ^(.*)$/index.php?/$1 [L]

I made a couple of changes to the code since my configuration is a bit different from the default. I'm not on the root so : 'RewriteBase /davidfrancoeur.com/' and I've renamed the CodeIgniter system folder for additional security so : RewriteCond %{REQUEST_URI} ^core.* RewriteRule ^(.*)$ /index.php?/$1 [L]

完成此操作后,所有内容均应正常运行,我应该能够毫无问题地访问http://localhost/david/Articles/,而且我认为我不应该直接与http://localhost/david/core/config/config.php联系.

With this done, anything should work properly, I should be able to access http://localhost/david/Articles/ without a problem and I think I shouldn't be able to reach http://localhost/david/core/config/config.php directly.

不幸的是,它不起作用,甚至看起来都没有完成任何重写.你看我在这里做错什么吗?有没有办法知道apache是​​否实际上重写了什么?

Unfortunately, it doesn't work, it doesn't even look like any rewriting is done. Do you see if I'm doing something wrong here? Is there a way to know if apache actually rewrite anything?

非常感谢.是的,我看了数以百万计的关于...的文章...:(

Thanks a lot. And yes I looked at the millions of article I could found about this... :(

编辑

CI 2.0.2,PHP 5.3,Apache 2.2

CI 2.0.2, PHP 5.3, Apache 2.2

推荐答案

仔细查看我的Zend社区服务器的httpd.conf之后,我意识到有两个<Directory />指令.问题中第一个是空的,第二个是这样的:

After looking carefully into the httpd.conf of my Zend Community Server, I realized that there was two <Directory />instruction. The first one was empty as shown in the question and the second one looked like that :

<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`,并且可以正常工作.对于那些想进一步了解使用CodeIgniter进行URL重写的人,请查看: http://codeigniter.com/wiki/mod_rewrite/

I changed the following line AllowOverride None to AllowOverride All` and it worked. For those who would like to know more about URL rewrite with CodeIgniter look there : http://codeigniter.com/wiki/mod_rewrite/

并正确理解AllowOverride的内容: http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride

再次感谢您的帮助!

这篇关于CodeIgniter删除index.php apache mod_rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆