【问题标题】:Having a hard time rewriting codeigniter uri's很难重写codeigniter uri
【发布时间】:2014-07-10 00:44:58
【问题描述】:

我在网上浏览了一些 codeigniter 教程,但我被困在重写 uri 上。

这是我的 .htaccess 代码。

RewriteEngine On
RewriteBase jrdash

RewriteCond %{REQUEST_URI} ^system.*
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]

我也对配置文件进行了此更改。

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

.htaccess 文件位于根项目文件夹中,项目目录是我的 xampp htdocs 目录中的 jrdash。当我尝试通过键入 localhost/jrdash 来加载页面时出现错误,我之前获得了默认的 Codeigniter 屏幕,但后来我进行了这些更改,现在我得到了一个错误。

【问题讨论】:

  • 每个重写规则中index.php 之后的? 是什么?此外,除非您使用别名目录,否则很少需要 RewriteBase。我建议删除它
  • 我不确定,我从正在看的教程中复制了代码。
  • 呃,你必须观看的任何教程(我认为它是 phpcodeacademy YouTube 频道中那些糟糕的视频之一)都不值得关注。
  • 我在 Udemy 上观看 BrutalStorm 的 PHP Codeigniter。不知道如何学习 Codeigniter,所以我认为这将是一个好的开始。有什么建议吗?
  • @Phil .htaccess 不是我的强项,但这个问号使我的一些项目在某些托管环境中正常工作,如果没有它,它们将失败

标签: php apache .htaccess codeigniter mod-rewrite


【解决方案1】:

我建议你删除第一行和最后三行之间的所有内容并删除那个问号。

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

【讨论】:

  • 那改变了错误信息,我得到一个内部服务器错误
  • @user2684521 你的 Apache 错误日志是怎么说的? -d 标志的大小写错误。我已经解决了
  • [Wed Jul 09 17:58:54 2014] [error] [client ::1] 由于可能的配置错误,请求超出了 10 个内部重定向的限制。如有必要,使用“LimitInternalRecursion”增加限制。使用“LogLevel debug”获取回溯。
  • @user2684521 这很奇怪。这是唯一的.htaccess 文件吗?它在您的jrdash 目录中吗?
  • 是的,但在应用程序目录中还有一个 .htaccess 文件,该文件只是拒绝所有
【解决方案2】:

我没有阅读您的整个问题,因为我很确定您犯了一个非常经典的错误:您忘记添加 QSA 指令!

RewriteEngine On
RewriteBase jrdash

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-10
    • 2016-05-08
    相关资源
    最近更新 更多