【问题标题】:CodeIgniter: rewriting URL's with .htaccessCodeIgniter:用 .htaccess 重写 URL
【发布时间】:2013-12-15 13:52:47
【问题描述】:

我已经使用带有多个控制器的 CodeIgniter 构建了一个应用程序

我希望应用程序 URL 使用 .htaccess 文件看起来“漂亮”。
除了在“application/config/routes.php”文件中设置为默认的控制器之外,所有控制器似乎都可以正常工作

我的 .htaccess 文件如下所示:

重写引擎开启
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
重写规则 ^(.*)$ /index.php/$1 [L]

我也设置了这样的config.php文件

$config['index_page'] = '';

在服务器日志中,我收到如下错误:

[2013 年 11 月 29 日星期五 10:32:11] [错误] [客户端 ... ] mod_security:过滤请求的 POST 有效负载,但有效负载不可用 [hostname "app.*.nl"] [uri "/user/profile"]

在开发服务器上一切正常,但自从应用程序在生产服务器上后,它就无法使用 .htaccess 文件。

【问题讨论】:

    标签: php apache .htaccess codeigniter mod-rewrite


    【解决方案1】:
    AddDefaultCharset UTF-8
    
    RewriteEngine On
    
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} ^codeigniter.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      • 2013-01-24
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      相关资源
      最近更新 更多