0

我在 Windows(使用 WampServer)上使用 CodeIgniter 和 mod_rewrite(仅用于抽象索引)创建了一个应用程序。在那种环境下,应用程序运行良好,一切正常。但是当我将它移植到生产服务器(Linux)时,重写过程刚刚停止工作。

乍一看,在我看来,linux 文件系统的“区分大小写”就是小丑。但是在重命名包含错误的文件后,问题仍然存在。

事实上。无论我调用哪个 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)
4

2 回答 2

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>
于 2013-11-11T18:11:03.390 回答
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 的回答为基础,再挖掘一点,我得到了上面的配置。它本身并没有完全解决整个问题,但重写部分完全解决了。整个问题的部分原因是重写引擎不知道正确重定向,另一部分是文件系统的“区分大小写”。我不知道这是否是最好的解决方案,但我创建了一些指向我的主控制器和模型的符号链接,一切正常。符号链接方法起作用了,因为我的控制器文件名为“c.php”,所以我创建了一个“C.php”符号链接,并且可以完成每个请求而不必担心区分大小写。

于 2013-11-13T11:38:22.550 回答