Codeigniter 默认控制器不工作

发布于 2025-01-01 01:24:01 字数 768 浏览 0 评论 0原文

我几乎已经使用 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

默认控制器出现。是否有缺少的配置?如果有人可以在网上指出有关此问题的任何参考资料,那就足够了。如果我需要添加其他信息,请告诉我。谢谢先生,我真的很感激。

I have almost finished a web application using Codeigniter. In development, the root directory is /readme/ and I use the following code in .htaccess to eliminate index.php in the URL:

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]

I also set Readme_home as the default controller, so the following URL will directly points to the default controller:

http://localhost/readme

For production, I use the exact same configuration as the one for development but the following URL does not work and produce 'Directory access is forbidden' error:

http://www.mydomain/readme

Instead, I have to use

http://www.mydomain/readme/readme_home

for the default controller to appear. Is there any missing configuration? If anyone can point out any reference on the web about this problem, that would be good enough. Let me know if I have to add additional information. Thank you sir, and I really appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光无声 2025-01-08 01:24:01

尝试:

$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';

Try:

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

Depending on your host, your uri_protocol might not be detected properly. In your config/config.php file, switch uri_protocol to any of the options listed. I've had the same issue when running my app on a VPS. Currently, PATH_INFO works.

/*
|--------------------------------------------------------------------------
| 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';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文