php - CodeIgniter + mod_rewrite url重写错误

标签 php linux .htaccess codeigniter mod-rewrite

我在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)

最佳答案

    <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>

关于php - CodeIgniter + mod_rewrite url重写错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19911780/

相关文章:

c - fork exec 等待命令行输入值的循环

php - 使用正则表达式阻止 .htaccess 中的 URL

html - 使用 htaccess 重写规则重定向后 CSS 未加载

php - 如何在php中对日期数组进行排序?

php pdo 哪里请求对给定值不起作用?

linux - 如何仅编译 ARM32 二进制文件(没有拇指)

linux - 我可以在没有 cron 或 incron 的 Linux 服务器上连续运行 inotifywait

php - 将子域重定向到 CakePHP 操作

php - 如何使用 sql 数据库向此代码添加谷歌地图信息面板

php - laravel 查询生成器 : join dependent on primary content