【问题标题】:Codeigniter giving 404 but htaccess correctCodeigniter 给出 404 但 htaccess 正确
【发布时间】:2015-12-09 09:22:19
【问题描述】:

我正在使用 Codeigniter 3 并拥有以下 htaccess 文件:

RewriteEngine on

# Allow redirect.phps which are setup 
RewriteCond %{REQUEST_URI} register.php
RewriteRule ^/?([A-Za-z]{2})/register.php /redirect.php/$1 [NC,L]
RewriteRule ^/?register.php /redirect.php/uk [NC,L]

RewriteRule ^/?([A-Za-z]{2})/images/(.*)$ /images/$1/$2 [NC,L]

RewriteCond %{REQUEST_URI} !^/images/([^/]+)/ [NC]
RewriteCond $1 !^(index\.php|css|jscript|convert\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

我在http://htaccess.mwl.be/ 上测试过,格式正确,有人告诉我:

太好了。但由于某种原因,我得到了 Codeigniter 404 页面?? Codeigniter 肯定永远不会看到我的代码吗?如果我在 index.php 文件中放一个简单的 hello+exit ,我可以清楚地看到 Codeigniter 正在传递参数,那么我到底做错了什么?

【问题讨论】:

  • 您是否尝试在 config.php 文件中设置 $base_url?
  • 是的 - 它设置为 $config['base_url'] = 'my.local';
  • 好的,假设您的应用程序位于您的根目录中,请尝试更改 .htaccess 像这样<IfModule mod_rewrite.c> RewriteEngine On 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] RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L] </IfModule>
  • @Ukuser32 你的网址是什么?
  • 应该是 my.local - 我在本地测试它

标签: .htaccess codeigniter mod-rewrite


【解决方案1】:

尝试像这样更改您的.htaccess

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

或者这个

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

【讨论】:

  • 那太好了@Niranjan,谢谢。我已经尝试了后半部分并替换了我的 Codeigniter 位,但我认为我的原始文件的 [L] 应该已经停止了 Codeigniter 规则的实际匹配,这是不对的吗?为什么会到那个地步?
猜你喜欢
  • 1970-01-01
  • 2012-02-25
  • 1970-01-01
  • 2012-11-10
  • 2012-02-15
  • 2022-09-22
  • 1970-01-01
  • 2018-03-20
  • 1970-01-01
相关资源
最近更新 更多