简体   繁体   English

如何在CodeIgniter的url中隐藏控制器名称?

[英]How to hide controller name in the url in CodeIgniter?

so the thing is I'm using .htaccess to hide the index.php but I still get the controller name in the url like that: http://example.com/name_controller/about My question is: is it possible to hide the name of the controller, so that only method is shown? 所以我正在使用.htaccess隐藏index.php,但我仍然在网址中获取控制器名称: http//example.com/name_controller/about我的问题是:是否可以隐藏控制器的名称,以便只显示方法? hxxp://example.com/name_controller/about hxxp://example.com/name_controller/about

You can define a custom route in config/routes.php - for example: 您可以在config / routes.php中定义自定义路由 - 例如:

$route['about'] = 'name_controller/about';

Then, http://example.com/about
goes to http://example.com/name_controller/about

See Hiding the controller's method name in the URL? 请参阅在URL中隐藏控制器的方法名称? in the CI forums for more information. 在CI论坛中获取更多信息。

您可以在/system/application/config/routes.php文件中添加一个条目:

$route['about'] = "controller_name/about";

I did it like this: (config/routes.php) 我是这样做的:(config / routes.php)

Code: $route['((photos|blogs).+)'] = "$1"; 代码:$ route ['((照片|博客)。+)'] =“$ 1”;

$route['([a-zA-Z0-9_-]+)'] = "user/profile/$1"; $ route ['([a-zA-Z0-9 _-] +)'] =“user / profile / $ 1”;

it is ok correct solutions for common. 这是正确的解决方案。

$route['default_controller'] = "xxx"; $ route ['default_controller'] =“xxx”;

home

$route[' home '] = " xxx/home "; $ route [' home '] =“ xxx / home ”;

function_name/parameter0/parameter1/parameter2 函数名/ parameter0 /参数1 /参数2

$route[' Collection/(:any) '] = " xxx/Collection/$1 "; $ route [' Collection /(:any) '] =“ xxx / Collection / $ 1 ”;

You can add below code in the /application/config/routes.php file: 您可以在/application/config/routes.php文件中添加以下代码:

$route['default_controller'] = "Home";
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

$route['(?i)about'] = "Home/about";
$route['(?i)login'] = "Home/Login";
$route['(?i)products'] = "ProductController/ProductList";
$route['(?i)addproduct'] = "ProductController/AddProduct";
$route['(?i)editproduct'] = "ProductController/EditProduct";
$route['(?i)products/(:any)'] = "ProductController/ProductList/$1";//search product list perameters.

100% It work.. 100%它工作..

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM