简体   繁体   中英

How to separate same directory - controller name in Codigniter

I've got a controller called course and a directory with the same name, and when I request

my_site/course

it redirects my to the directory course Instead of controller, how can I redirect to the controller
PS It's very necessary to keep directory with the same name in my apllication

Does the directory need to be int he root folder, can it not be further down the hierarchy? By having a directory with the same name as your controller in the root directory, your web server is serving up the directory instead of normal CodeIgniter routing.

If it's an absolute must to have the folder in the root, then you would need to change your .htaccess file to ignore requests which match the directory name for that directory (and any others which match controller names).

There's an answer for this already, as well as a good example on the Drupal website which I've put in below in case it gets moved

=========[ start of .htaccess snippet]==========
<IfModule mod_rewrite.c>
    RewriteEngine on
    #
    RewriteCond %{REQUEST_URI} !^/yourDirectoryName
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>
====================[ end ]=====================

There nativ Ci routing.

In config/routes.php

$route['course'] = 'controller/course';

  • after default routes

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