Codeigniter框架中的URL更改

时间:2015-01-26 11:13:12

标签: codeigniter

我有一个网址

http://localhost/himalaya/webmanager/recentUpdate/index/edit-recent-update-1

但我想让它像这样制作网址:

http://localhost/himalaya/webmanager/recentUpdate/edit-recent-update-1.

控制器名称为recentUpdate,方法名称为index。我的问题是如何在codeigniter框架中从URL中删除index方法名称?

2 个答案:

答案 0 :(得分:0)

嗨首先,您只需阅读codeigniter中index.php的工作原理。 https://ellislab.com/codeigniter/user-guide/general/urls.html

要删除索引,请在.htaccess文件中编写路由规则。 在应用程序文件夹

之上

RewriteEngine On

RewriteBase / project_name /

RewriteRule ^(。*)$ index.php?/ $ 1 [L]

答案 1 :(得分:0)

在项目中添加.htaccess文件。

在其中添加代码。

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]