【问题标题】:Codigniter Mod_Rewrite not working in WAMPCodeigniter Mod_Rewrite 在 WAMP 中不起作用
【发布时间】:2013-04-26 06:32:30
【问题描述】:

我在 WAMP 上使用 CodeIgniter。 Apache 的 Mod_Rewrite 模块被加载。 我的 CI 项目位于 C:\wamp\www\store 我已经从 Codeigniter URL 文档 (here) 中复制了重写规则:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

我要打开的链接是localhost/store/city 在我看来,这条规则永远不会触发。当我尝试打开上述地址时,我收到了我的浏览器(不是 CI)的默认 404 并且似乎没有发生重写。 如果我加载 localhost/store/index.php/city 会加载正确的页面。 为什么我的规则不会触发?

【问题讨论】:

标签: php .htaccess codeigniter mod-rewrite wamp


【解决方案1】:

尝试改变

RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteRule ^(.*)$ ./index.php/$1 [L]

您的方法试图从基础加载 URL

localhost/index.php/city

【讨论】:

  • 问题似乎是规则没有触发。好像正则表达式不匹配。
【解决方案2】:

在您的 .htaccess 文件中使用此代码:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

这肯定会帮助你:)

【讨论】:

  • 问题似乎是规则没有触发。好像正则表达式不匹配。
【解决方案3】:

在 application/config/config.php 中,您必须将索引页设置为空白,例如:

$config['index_page'] = '';

【讨论】:

    【解决方案4】:

    我把这条规则放在了文件里:

    RewriteRule (.*) http://test.com
    

    事实证明,重写规则根本没有触发。需要移动 .HTaccess 文件。 CI 将其放置在 Application 文件夹中。我把它拖出父文件夹,现在一切正常。 奇怪的事情。

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 2014-01-11
      • 2010-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-20
      相关资源
      最近更新 更多