代码中的路由问题 [英] routing problem in codeigniter

查看:152
本文介绍了代码中的路由问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CodeIgniter和路由的新用户。

I'm new to CodeIgniter and routing.

我有一个登录 c> index()加载视图以输入用户名/密码。在视图中,窗体具有 action =login / authenticate。 Login-> authenticate()确定登录是否有效。如果有效, redirect('lobby'),如果不是 redirect('login')

I have a Login controller whose index() loads up a view to enter a username/password. In the view, the form has action="login/authenticate". Login->authenticate() determines if the login is valid or not. If it's valid, redirect('lobby'), if not redirect('login')

routes.php:

routes.php:

$route['default_controller'] = "login"

config.php:

config.php:

$config['base_url'] = "http://localhost/dts/";
$config['index_page'] = "index.php";

问题是,当我去 http:// localhost / dts / ,点击登录,我正确(?)重定向到 http:// localhost / dts / login / authenticate c $ c>找不到对象!。但是当我去 http://localhost/dts/index.php/ (带斜杠),它工作正常(我被重定向到 http://localhost/dts/index.php/login/authenticate ,并且已登录)

The problem is that when i go to http://localhost/dts/ , click login, I am correctly (?) redirected to http://localhost/dts/login/authenticate but the browser says Object not found!. But when I go to http://localhost/dts/index.php/ (with trailing slash), it works correctly (I get redirected to http://localhost/dts/index.php/login/authenticate, and am logged in)

我尝试删除index.php 通过使用.htaccess:

I tried removing "index.php" by using a .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

,即使 http:// localhost / dts /

我很困惑..发生了什么事?

I'm confused.. what's going on?

推荐答案

问题是您的.htaccess文件的最后一行。

The issue is with the last line of your .htaccess file.

由于您的应用程序位于子目录(dts)中,index.php前面的正斜杠不工作。尝试删除它,以使您的文件看起来像这样:

Since your application is in a subdirectory ("dts"), the forward slash in front of the "index.php" won't work. Try removing it so that your file looks like this:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

这篇关于代码中的路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆