【问题标题】:How to hide controller name in the url in CodeIgniter?如何在 CodeIgniter 的 url 中隐藏控制器名称?
【发布时间】:2010-06-07 16:34:01
【问题描述】:

所以问题是我正在使用 .htaccess 隐藏 index.php 但我仍然在 url 中获得控制器名称:http://example.com/name_controller/about 我的问题是:是否可以隐藏控制器的名称,以便只显示方法? hxxp://example.com/name_controller/about

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

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

    首页

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

    function_name/parameter0/parameter1/parameter2

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

        您可以在 config/routes.php 中定义自定义路由 - 例如:

        $route['about'] = 'name_controller/about';
        
        Then, http://example.com/about
        goes to http://example.com/name_controller/about
        

        有关详细信息,请参阅 CI 论坛中的 Hiding the controller’s method name in the URL?

        【讨论】:

        • 所有页面都需要这样做吗,没有任何自动化的解决方案可以默认将规则应用于所有路由吗?
        【解决方案4】:

        我是这样做的:(config/routes.php)

        代码: $route['((照片|博客).+)'] = "$1";

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

        对于常见的正确解决方案是可以的。

        【讨论】:

        • 请尽量把最后一句话说清楚,听起来很不清楚
        【解决方案5】:

        您可以在 /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% 有效..

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-09-08
          • 1970-01-01
          • 1970-01-01
          • 2013-09-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多