【问题标题】:codeigniter 404 error代码点火器 404 错误
【发布时间】:2011-09-27 10:50:12
【问题描述】:

我已经创建了一个 codeigniter 网站。我的默认控制器是 $route['default_controller'] = "login";在 routes.php 中

我的基本 URL 是 $config['base_url'] = 'http://digimed.net/sandbox/';在config.php中

场景 A 我在 URL 栏中键入 http://digimed.net/sandbox/ 我得到了登录控制器的索引方法,如预期的那样。

场景 B 我输入http://digimed.net/sandbox/login 之类的内容,但我预期与场景 A 中的结果相同时出现 404 错误。

事实上,我无法访问登录控制器中的任何功能。我每次都会收到 404 错误。

我需要在路线或 congig 中更改什么吗?

谢谢

【问题讨论】:

  • 你设置了webserver的重写规则吗?
  • 嗯,不是特别没有。我该怎么做?
  • 尝试将您的浏览器指向digimed.net/sandbox/index.php/login,如果它可以正常工作,则意味着您错过了重写规则,请参阅 Kevin 的回答

标签: php http-status-code-404


【解决方案1】:

如果有人感兴趣,我通过在网站路由目录(codeigniter 路由目录所在的位置)中添加以下 .htaccess 文件来解决问题

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /system_admin

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

【讨论】:

  • @Kevin RewriteBase 的 system_admin 是什么?我网站的 URL 类似于 subdomain.example.com,文件放在我的根文件夹中。如果有,RewriteBase 应该是什么?
  • @NaveedS 我不确定如何将 RewriteBase 用于子域,但在我的情况下,我使用它将我的安装标记为 example.com/system_admin。我的文件位于 example.com 目录中名为 system_admin 的文件夹中
猜你喜欢
  • 2015-02-20
  • 2016-03-15
  • 2016-01-13
  • 1970-01-01
  • 2016-07-26
  • 2018-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多