在 Codeigniter-HMVC 项目中以标准方式管理 URL

Managing URLs in a standard way in Codeigniter-HMVC project

我已经在 codeigniter-HMVC 中开发了项目,现在我想以标准方式管理 url。

我当前的网址:

http://xyz/home/contactus
http://xyz/home/aboutus
....
....

我想要像:

http://xyz/contactus
http://xyz/aboutus
....
....

我正在使用 HMVC codeigniter 结构。

在你的 route.php 文件中你可以像这样重定向

$route['xyz/contactus'] = "xyz/home/contactus";

您可以在 routes.php

中定义自定义路由
$route['contact-us'] = "home/home/contactus";
          ^              ^     ^        ^
        New URL      module  Controller  Method

在 URL 中调用 xyz/contact-us' 可以正常工作

Read more about CodeIgniter route

[project-folder]/application/config/routes.php

编辑 routes.php

要将 URI 路由为虚拟控制器和虚拟方法,您可以使用选项路由来实现。路由 URI 的主要用途是使 url 漂亮并停止显示用户主控制器,并且可以通过路由实现方法名称。

语法

$route['dummy-controller/dummy-method'] = 'main_controller/main_method';

示例

$route['contact-us']='index.php/home/contactus';