简体   繁体   English

如何分隔同一目录-Codigniter中的控制器名称

[英]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 当我请求时,我有一个名为Course的控制器和一个具有相同名称的目录

my_site/course my_site /课程

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 PS在我的应用程序中,保持目录名称相同是非常必要的

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. 通过在根目录中拥有一个与控制器名称相同的目录,您的Web服务器将为该目录提供服务,而不是正常的CodeIgniter路由。

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). 如果绝对要在根目录中包含该文件夹,那么您将需要更改.htaccess文件,以忽略与该目录的目录名称匹配的请求(以及与控制器名称匹配的其他任何请求)。

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 已经有一个答案 ,以及在Drupal网站上的一个很好的例子,我将其放在下面,以防它被移动

=========[ 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. 有nativ Ci路由。

In config/routes.php 在config / routes.php中

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

  • after default routes 默认路线之后

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

相关问题 由于目录名称相同,未调用codeigniter控制器 - codeigniter controller not being called due to directory with same name 如何具有相同名称的文件和目录 - How to Have a File and Directory With Same Name RewriteRule 与目录同名 - RewriteRule same name as directory 如何使用.htaccess重写规则命名文件和目录? - How to name file and directory the same with .htaccess rewrite rules? 如何将具有相同名称的文件重定向到其他目录? - How can I redirect a file with the same name to a different directory? 当站点在单独的目录中具有门户网站的asp.login页面时,如何更改wordpress域名? - How to change wordpress domain name when site has asp.login page for portal in a separate directory? 如何将域名指向您站点内的子目录,并使其看起来像是一个单独的实体? - How to point a domain name to a sub-directory within your site and have it so that it looks as if it is a separate entity? 清理路径与目录同名 - Clean path with the same name as a directory 如果同一目录下的文件名和文件夹名相同,如何从 URL 中删除 .html 扩展名 - How can you remove the .html extension from a URL if you have the same file name and folder name on the same directory .htaccess,正确重写同名目录和文件 - .htaccess, proper rewriting of directory and file with same name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM