简体   繁体   中英

CodeIgniter Routing Not Working in Sub Directory

I have setup a CodeIgniter site but only the default routing seems to be working.

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.

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 :

The requested URL /subdir/users/login was not found on this server. Apache/2.4.25 (Win32) OpenSSL/1.0.2k PHP/5.4.44 Server at apps.mediaforce.co.uk Port 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.

Hence update your $route['users/login'] to route to following:

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

Edit 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:

RewriteEngine on

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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