简体   繁体   English

Codeigniter所有URL都转到默认控制器

[英]Codeigniter all URLs go to default controller

I'm testing my php app built with Codeigniter on local host (wamp). 我正在测试我在本地主机(wamp)上使用Codeigniter构建的php应用程序。 In Firefox all my URLs go to my default controller unless I add a trailing slash. 在Firefox中我的所有URL都转到我的默认控制器,除非我添加一个尾部斜杠。

eg site.com/controller/method/ 例如site.com/controller/method/

Even methods not expecting a third URI segment are redirected. 甚至不期望第三个URI段的方法也会被重定向。 Does anyone know the reason behind this? 有谁知道这背后的原因?

Update 更新

application/config/routes.php 应用/配置/ routes.php文件

$route['default_controller'] = "pages"; //loads homepage view
$route['404_override'] = '';

I'm not using .htaccess on localserver 我没有在localserver上使用.htaccess

You mentioned you are not using .htaccess but without rewriting /controller/method/ into appropriate path your application will fail. 您提到您没有使用.htaccess但没有重写/controller/method/进入适当的路径,您的应用程序将失败。 Usual .htaccess file for a CodeIgniter application should contain at least the following configuration for rewriting CodeIgniter应用程序的常用.htaccess文件至少应包含以下重写配置

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

Change your URL like this. 像这样更改您的网址。 This is default URL. 这是默认URL。

site.com/index.php/controller/method/ site.com/index.php/controller/method/

If you are configured .htaccess 如果您配置了.htaccess

site.com/controller/method/ this url is correct site.com/controller/method/这个网址是正确的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM