【问题标题】:Codeigniter default controller not workingCodeigniter 默认控制器不起作用
【发布时间】:2012-02-01 05:45:14
【问题描述】:

我几乎已经使用 Codeigniter 完成了一个 Web 应用程序。在开发中,根目录是/readme/,我在.htaccess中使用以下代码来消除URL中的index.php:

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

我还设置了Readme_home为默认控制器,所以下面的URL会直接指向默认控制器:

http://localhost/readme

对于生产,我使用与开发完全相同的配置,但以下 URL 不起作用并产生“禁止访问目录”错误:

http://www.mydomain/readme

相反,我必须使用

http://www.mydomain/readme/readme_home

默认控制器出现。有没有遗漏的配置?如果有人可以在网络上指出有关此问题的任何参考,那就足够了。如果我必须添加其他信息,请告诉我。谢谢先生,我真的很感激。

【问题讨论】:

  • 检查文件夹和文件的权限,它必须是可读的网络访问(例如chmod 666)。有关该主题的更多信息,请通过search engine
  • 我认为这不是权限问题。您是否尝试过使用标准的 .htaccess 脚本(或没有 .htaccess 文件)并将配置中的 base_url 更改为“mydomain.com/readme”?我认为 CI 应该自己解决剩下的问题。
  • 我实际上尝试了这两种方法,但都不起作用。还是谢谢:)

标签: php codeigniter controller


【解决方案1】:

试试:

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

根据您的主机,您的uri_protocol 可能无法正确检测到。在您的 config/config.php 文件中,将 uri_protocol 切换到列出的任何选项。在 VPS 上运行我的应用程序时,我遇到了同样的问题。目前,PATH_INFO 有效。

/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of 'AUTO' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'            Default - auto detects
| 'PATH_INFO'       Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'     Uses the REQUEST_URI
| 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'PATH_INFO';

【讨论】:

  • 我也试过了,但还是不行。我同意这可能是 codeigniter 配置或 .htaccess。还有其他想法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-24
  • 2015-04-02
  • 2013-10-22
相关资源
最近更新 更多