codeigniter 301重定向与路由器为旧url和remaning没有重定向 [英] codeigniter 301 redirect with router for old url and remaning no redirect

查看:203
本文介绍了codeigniter 301重定向与路由器为旧url和remaning没有重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个codeigniter网站,为此我正在做搜索引擎优化,所以问题是大多数网址缓存在搜索引擎,我的旧网址是

I have a codeigniter site, for which i am doing SEO, so the issue is most of the urls are cached in search engines, what my old url is

/product/details/productname/productid

我的新网址

/tours/cityname/productname

我想要将旧的网址重定向到新的网址为301,新产品网址不会被重定向为301,因为它们是新的,并且具有相同的网址结构,因为我搜索codeigniter站点关于url路由在router.php,它给出一个例子为重定向

I want for my old urls to be redirected to new with 301, and new product url not to be redirected with 301 as they are new and will have the same url structure, as I search on codeigniter site about url routing in router.php, which gives an example for redirection as

$route['product/(:num)'] = "catalog/product_lookup_by_id/$1";

我认为这里我可以进行更改,但我怎么能做一个301在这种模式,通过使用头或有更好的方法这样做?

I think that this where i can make the change but how can i do a 301 in this pattern, by using header or is there a better way of doing this ?

推荐答案

我最近面临着一个非常类似的情况。
要将404从所有结果保存在Google&链接的网站,我保持旧路由,但指向一个新的控制器/功能。 Theis函数管理301重定向。

I was faced with a very similar situation recently. To save the 404 from all the results at Google & linked sites, I kept the old route but pointed it at a new controller/function. Theis function manages the the 301 redirection.

    public function oldurl_to_newurl()
    {
          $newURL = LogicToGetNewURL
          redirect($newURL,'location',301);
    }

使用旧URL的段,我查询数据库并创建新的URL。然后它相应地重定向用户。这也是我能够跟踪我的分析的一些指标。

Using the segments from the old URL, I query the database(if needed) and create the new URL. It then redirects the users accordingly. This was I am also able to track the some metrics for my analytic.

这篇关于codeigniter 301重定向与路由器为旧url和remaning没有重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆