【问题标题】:Url route in codeigniter notworkingcodeigniter中的网址路由不起作用
【发布时间】:2015-07-09 13:58:48
【问题描述】:

application/config/routes.php

       $route['aboutus'] = 'footerpage/index/$2';

网址路由概念在 codeigniter 中不起作用。 在这里尝试我将 url footerpage/index/1 更改为 aboutus

网址就像

        http:local.com/footerpage/index/1

想成为这样的人

       http:local.com/aboutus

【问题讨论】:

  • 您的其余路由是否适用于该站点?
  • 1 来自哪里local.com/footerpage/index/1

标签: codeigniter url routes


【解决方案1】:

我猜你正在寻找这个?

$route['footerpage/index/[0-9]+'] = "aboutus";

我假设索引后的数字会有所不同......但是如果不改变这样的值,您可以将[0-9]+ 更改为1

$route['footerpage/index/1'] = "aboutus";

希望对你有帮助

【讨论】:

  • 在 aboutus 之前添加一个斜杠,就像这样 $route['footerpage/index/1'] = "/aboutus";
  • 运气好吗?
【解决方案2】:

只需使用 .htaccess,如下所示:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^local.com[nc]
RewriteRule ^(.*)$ http://www.local.com/$1 [r=301,nc]
Redirect 301 /footerpage/index/1 /aboutus

【讨论】:

    【解决方案3】:

    根据我的理解,1 是来自数据库的 id,它不会改变,所以在你的控制器“footerpage”和“index”函数中,你可以直接将 id 设为 1...无需在路由中定义 id

    在路线中

    $route['aboutus'] = 'footerpage/index';
    

    【讨论】:

      【解决方案4】:

      你应该试试这个:

      $route['aboutus/(:any)'] = 'footerpage/index/$2';
      

      uri 将显示作为变量传递给控制器​​的参数。

      【讨论】:

        猜你喜欢
        • 2019-05-03
        • 2012-06-24
        • 1970-01-01
        • 2011-11-07
        • 2018-06-27
        • 1970-01-01
        相关资源
        最近更新 更多