【问题标题】:Codeigniter URL rewriting .htaccess is not working on CentOSCodeigniter URL 重写 .htaccess 在 CentOS 上不起作用
【发布时间】:2014-01-09 17:25:10
【问题描述】:

我在我的文档根目录/var/www/html/ 中创建了一个 .htaccess 文件来重写 Codeigniter 的 URL 以从所有页面的 URL 中删除“index.php”。

例如更改网址

http://myhost/index.php/controller/function

http://myhost/controller/function`

这是我的`/var/www/html/.htaccess 的代码

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

我从谷歌上得到了很多关于启用 mod-rewrite 模块的建议,但我可以在我的 httpd.conf 中看到它已经启用。

LoadModule rewrite_module modules/mod_rewrite.so

这在我在 Debian 7 (Apache/2.4.4) 上运行的本地系统上完美运行。

任何帮助将不胜感激。 :)

【问题讨论】:

    标签: linux apache .htaccess codeigniter mod-rewrite


    【解决方案1】:

    您的 centos 服务器可能未设置为处理 PATH INFO。尝试将规则目标中的 index.php/$1 替换为 index.php?/$1

    然后您需要修改 CI 配置以启用查询字符串:http://ellislab.com/codeigniter/user-guide/general/urls.html

    在你application/config.php文件中设置$config['enable_query_strings']TRUE

    【讨论】:

      【解决方案2】:

      您还需要指定可以使用它的位置。例如,在 /etc/httpd/conf/httpd.conf 中,您应该看到如下内容:

      <Directory "/var/www/html">
      
            ...lots of text...
      
      </Directory>
      

      确保有:

      <Directory "/var/www/html">
      
          AllowOverride All
      
      </Directory>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-03
        • 2014-08-08
        • 2011-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多