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

时间:2022-05-09 11:03:57

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
P.S It's very necessary to keep directory with the same name in my apllication

它重定向到目录课程而不是控制器,如何重定向到控制器P.S在我的应用程序中保持同名目录是非常必要的

2 个解决方案

#1


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 ]=====================

#2


There nativ Ci routing.

有nativ Ci路由。

In config/routes.php

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

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

  • after default routes
  • 在默认路由之后

#1


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 ]=====================

#2


There nativ Ci routing.

有nativ Ci路由。

In config/routes.php

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

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

  • after default routes
  • 在默认路由之后