codeIgniter:是否可以删除控制器和放大器;使用路由或.htaccess中的URL功能?放大器、路由、控制器、功能

2023-09-02 20:34:38 作者:誓言、不过是变相的敷衍

我具有由一个称为页表中的一个数据库。 我有一个名为地盘控制器和一个名为页功能...... http://website.com /网站/网页/ PAGE_ID 。

在页面函数它目前查找3TH URI段(PAGE_ID),则查找并在数据库中匹配该一个页面一行并显示该行的结果。

我的问题是,是有可能的路线/从 http://website.com/改变我的网址网站/网页/ PAGE_ID 以 http://website.com/page_id 。然后显然改变我的函数来找到第一个URI段??

我目前的.htaccess文件删除的index.php,看起来是这样的:

 < IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase / DB

#Removes用户访问到系统文件夹。
#Additionally这将允许您创建一个System.php控制器,
#previously这将是不可能。
#'系统'可以,如果你已重命名系统文件夹进行更换。
的RewriteCond%{REQUEST_URI} ^系统。*
重写规则^(。*)$ /index.php/$1 [L]

#Checks,查看是否用户正在试图访问一个有效的文件,
#such作为图像或CSS文档,如果这不是它发送的真实
#request的index.php
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
#这个最后一个条件可以访问图像和css文件夹,并且robots.txt文件
由迈克尔·Radlmaier #Submitted(mradlmaier)
的RewriteCond $ l ^(指数 .PHP |图片|机器人 .TXT | CSS)!
重写规则^(。*)$的index.php / $ 1 [L]
< / IfModule>

<!IfModule mod_rewrite.c>
#如果我们没有mod_rewrite的安装,所有404的
#可以被发送到index.php,一切工作正常。
#提交者:ElliotHaughin

的ErrorDocument 404的index.php
< / IfModule>
 

解决方案

看看的这篇文章。编辑routes.php文件在你的应用程序配置应该做的伎俩。像这样的东西应该工作:

  $航线['(:任何)] ='网站/网页/ $ 1';
 
房子太大WiFi不能覆盖 试试这几种方法

如果您使用额外的控制器,然而,更多的工作可能是必要的(我假设网站是你的控制器,即site.php位于应用程序/控制器)。

在code,你也可以考虑使用:NUM 而不是:任何如果你的页面ID是唯一的数字。

I have a database consisting of a table called "pages". I have a controller called "site" and a function called "page"... http://website.com/site/page/page_id.

In the page function it currently looks for the 3th URI segment (page_id), then finds and matches this to a page row in the database and displays the row results.

My question is, is it possible to route/change my URL from http://website.com/site/page/page_id to http://website.com/page_id. And then obviously change my function to find the first URI segment??

My current .htaccess file removes the "index.php", and looks like this:

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

解决方案

Take a look at this article. Editing the routes.php in your application config should do the trick. Something like this should work:

$route['(:any)'] = 'site/page/$1';

If you use additional controllers, however, more work might be necessary (I assume "site" is your controller, i.e. site.php is located in application/controllers).

In the code, you might also consider using :num instead of :any if your page IDs are only numeric.