Php CodeIgniter:是否可以卸下控制器&;使用routes或.htaccess从URL调用函数?

Php CodeIgniter:是否可以卸下控制器&;使用routes或.htaccess从URL调用函数?,php,.htaccess,codeigniter,Php,.htaccess,Codeigniter,我有一个数据库,由一个名为“pages”的表组成。 我有一个名为“站点”的控制器和一个名为“页面”的函数 在page函数中,它当前查找第三个URI段(page_id),然后查找并将其与数据库中的一个页面行匹配,并显示行结果 我的问题是,是否可以将我的URL从路由/更改为 . 然后很明显地改变我的函数来查找第一个URI段 我当前的.htaccess文件删除了“index.php”,如下所示: <IfModule mod_rewrite.c> RewriteEngine On Rewri

我有一个数据库,由一个名为“pages”的表组成。 我有一个名为“站点”的控制器和一个名为“页面”的函数

在page函数中,它当前查找第三个URI段(page_id),然后查找并将其与数据库中的一个页面行匹配,并显示行结果

我的问题是,是否可以将我的URL从路由/更改为 . 然后很明显地改变我的函数来查找第一个URI段

我当前的.htaccess文件删除了“index.php”,如下所示:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /db

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#‘system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn’t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don’t have mod_rewrite installed, all 404’s
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

重新启动发动机
重写基/db
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
#以前这是不可能的。
#如果已重命名系统文件夹,则可以替换“系统”。
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
#最后一个条件允许访问图像和css文件夹以及robots.txt文件
#Michael Radlmaier(mradlmaier)提交
1美元^(索引\.php | images | robots\.txt | css)
重写规则^(.*)$index.php/$1[L]
#如果我们没有安装mod_rewrite,所有404
#可以发送到index.php,一切正常。
#提交人:ElliotHaughin
ErrorDocument 404/index.php
看一看。在应用程序配置中编辑routes.php应该可以做到这一点。像这样的方法应该会奏效:

$route['(:any)'] = 'site/page/$1';
但是,如果使用其他控制器,可能需要做更多的工作(我假设“site”是您的控制器,即site.php位于应用程序/控制器中)


在代码中,您也可以考虑使用<代码>:Num < /C> >而不是<代码>:任何如果您的页面ID仅为数字。是的,你的权利,我有其他控制器和功能仍然需要工作。关于这件事,你能给我指出正确的方向吗?干杯。如前所述,如果您的页面ID是数字的,只需使用“(:num)”作为选择器。这样,(非数字)控制器名称就不会被匹配和重新路由。啊,为了简单起见,我放了page_id,但是我实际上使用了名称的seo版本,例如,page name作为选择器。。还有可能吗?为帮助干杯..路由是按定义的顺序运行的,因此您可能需要为所有控制器创建路由,然后将此路由放在路由文件的末尾。请阅读我链接到的文章。您可以使用正则表达式或路由的正确顺序(或两者的组合)来过滤某些应以常规/旧方式处理的页面。