【问题标题】:How to redirect old php routes in codeigniter如何在codeigniter中重定向旧的php路由
【发布时间】:2018-05-17 17:50:29
【问题描述】:

我有像http://example.com/products.php?s_productid=231 这样的旧网址,现在在我的项目中,网址是http://example.com/products/ver/231

如何在 routes.php 中制定规则进行重定向? 谢谢

【问题讨论】:

标签: codeigniter redirect routes


【解决方案1】:

你不需要对routes.php做任何改变,你只需要创建一个控制器“产品”,它有一个方法“ver”,它接收231(我猜是id)作为参数,比如这个:

defined('BASEPATH') OR exit('No direct script access allowed');

class Product extends CI_Controller {

    public function __construct(){
        parent::__construct();
    }

    public function ver($id) {
        // do your things
    }

希望对你有帮助。

【讨论】:

  • 在我的项目中,我有一个具有 ver($id) 功能的控制器产品,但是如果我在example.com/products.php?s_productid=231 中单击,则不会显示我正确的产品 231
  • 试试类似的东西? example.com/product/ver/231
【解决方案2】:

您可能需要在 config/routes.php 中设置路由

$route['product/ver/(:num)'] = 'product/ver/$1';

http://example.com/index.php/products/ver/231

然后是控制器

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Product extends CI_Controller {

public function __construct(){
    parent::__construct();
}

public function ver($id) {
    /*
       echo $id;
    */
}

【讨论】:

  • 我尝试过,但因为我也有公共函数 index() 来显示所有产品:example.com/products 我总是得到所有产品的列表。不是产品 231 或类似页面的页面
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-12
  • 1970-01-01
相关资源
最近更新 更多