[英]CodeIgniter routes: I keep getting a 404
I have a application/controller/login.php file containing the following 我有一个application / controller / login.php文件包含以下内容
class Login extends Controller {
function Login()
{
parent::Controller();
}
function index()
{
$this->mysmarty->assign('title', 'Login');
$this->mysmarty->assign('site_media', $this->config->item('site_media'));
$this->mysmarty->display('smarty.tpl');
}
}
My routes definition looks like the following: 我的路由定义如下所示:
$route['default_controller'] = "welcome";
$route['login'] = 'login';
$route['scaffolding_trigger'] = "";
The problem is that I keep getting a 404 when I try to access http://localhost/myapp/login . 问题是,当我尝试访问http:// localhost / myapp / login时,我一直收到404。 What did I do wrong?
我做错了什么? I've checked CI routes docs and cannot spot anything.
我检查了CI路线文档,但无法发现任何内容。
There shouldn't be anything wrong with this - does it work without the route? 这应该没有任何问题 - 没有路线会有效吗? Also, have you set the .htaccess properly (ie does http://localhost/myapp/index.php/login work instead)
另外,你有没有正确设置.htaccess(即http://localhost/myapp/index.php/login工作)
Another point to keep in mind, if you have have "enable_query_strings" set to true and aren't using the .htaccess mod_rewrite rules: 另请注意,如果您将“enable_query_strings”设置为true并且未使用.htaccess mod_rewrite规则:
In config/config.php: 在config / config.php中:
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
The URL to route your request properly would look like this: 正确路由您的请求的URL如下所示:
http://localhost/myapp/index.php?c=login
If you have not removed your index.php
from your app using the .htaccess
file, well thats another ball game on its own. 如果你还没有使用
.htaccess
文件从你的应用程序中删除你的index.php
,这就是另一个自己的球类游戏。 But what you can do is this: 但你能做的就是:
Set a default controller
that's not the welcome
file and if you want the welcome file to be your default use the link this way 设置一个不是
welcome
文件的默认controller
,如果您希望将欢迎文件作为默认文件,请使用此方式的链接
http://localhost/myapp/index.php/login
Remember this way only works when the index.php
file has not been removed using the .htaccess
file. 请记住,仅当使用
.htaccess
文件未删除index.php
文件时,此方法才有效。
Also open the apllication/config/config.php
and use this code for the baseurl
同时打开
apllication/config/config.php
并将此代码用于baseurl
$config['base_url'] = 'http://localhost/myapp';
That should always do the trick. 这应该总能解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.