简体   繁体   English

CodeIgniter路由在子目录中不起作用

[英]CodeIgniter Routing Not Working in Sub Directory

I have setup a CodeIgniter site but only the default routing seems to be working. 我已经设置了CodeIgniter网站,但似乎只有默认路由有效。

I have had to set it up as a sub dir of an overall site - so http://localhost/subdir is the default url - this seems to work with the basic out of the box routing. 我不得不将其设置为整个站点的子目录-所以http:// localhost / subdir是默认的URL-这似乎与基本的现成路由一起工作。

I have added a Users controller with the following methods - login, logout, register so I was expecting http://localhost/subdir/users/login would work but I get : 我使用以下方法添加了一个Users控制器-登录,注销和注册,因此我期望http:// localhost / subdir / users / login可以工作,但我得到了:

The requested URL /subdir/users/login was not found on this server. 在此服务器上找不到请求的URL / subdir / users / login。 Apache/2.4.25 (Win32) OpenSSL/1.0.2k PHP/5.4.44 Server at apps.mediaforce.co.uk Port 80 Apache / 2.4.25(Win32)OpenSSL / 1.0.2k PHP / 5.4.44服务器位于apps.mediaforce.co.uk端口80

My routes file is very basic so I tried adding a new route to it for the users controller but it made no difference. 我的路由文件非常基础,因此我尝试为用户控制器添加新路由,但没有任何区别。

$route['users/login'] = 'subdir/users/login';
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

Where am I going wrong? 我要去哪里错了?

You don't need to include subdir in your route. 您无需在路由中包含subdir

Hence update your $route['users/login'] to route to following: 因此,更新您的$route['users/login']路由至以下地址:

$route['users/login'] = 'users/login';

Edit 1: 编辑1:

in your root create a .htaccess file if it doesnot exist and save the following content in it to remove index.php from your URL: 在根目录中创建一个.htaccess文件(如果不存在),然后在其中保存以下内容,以从您的URL中删除index.php

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]

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

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