CodeIgniter + mod_rewrite url重写错误

时间:2013-11-11 16:58:42

标签: php linux .htaccess codeigniter mod-rewrite

我在Windows(使用WampServer)上使用CodeIgniter和mod_rewrite创建了一个应用程序(仅用于抽象索引)。在那个环境中,应用程序工作得很好,一切都很顺利。 但是当我将它移植到生产服务器(Linux)时,重写过程只是停止工作。

乍一看,我认为linux文件系统的“案例敏感性”是vilain。但在重命名包含错误的文件后,问题仍然存在。

事实是。无论我调用哪个url,重写都会一直调用/index.php。

这是我的.htaccess内容:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteRule .\svn\* - [F]

我的应用的文件夹结构是:

doc_root
  - application
    -controllers
       -c.php

  - .htaccess
  - index.php
  (... everything else is codeigniter's default)

2 个答案:

答案 0 :(得分:0)

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        RewriteCond %{HTTP_HOST} !^$
        RewriteCond %{HTTP_HOST} !^www\. [NC]
        RewriteCond %{HTTPS}s ^on(s)|
        RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

        #Removes access to the system folder by users.
        #Additionally this will allow you to create a System.php controller
        RewriteCond %{REQUEST_URI} ^system.*
        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>

答案 1 :(得分:0)

RewriteBase /
   RewriteCond %{ENV:REDIRECT_STATUS} 200
   RewriteRule .* - [L]



#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]


#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php/$1 [L]


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

以Kenzo的答案为基础,再挖掘一点,我对上面的配置感到满意。它本身并没有完全解决整个问题,但重写部分完全解决了。整个问题是由重写引擎不知道正确重定向的一部分引起的,另一部分是文件系统的“区分大小写”。我不知道它是否是最好的解决方案,但我创建了一些符号链接到我的主控制器和模型,一切正常。符号链接aproach工作因为我的控制器文件名是“c.php”,所以我创建了一个“C.php”符号链接,并且每个请求都可以完成,而不必担心区分大小写。

相关问题