将旧产品重定向到新产品(Opencart)(HTACCESS)

时间:2013-08-08 11:43:20

标签: .htaccess opencart

我想将旧的产品ID重定向到新的产品ID。

例如: 来自:h * tp://www.mysite.com/index.php?route = product / product& product_id = 50 to:h * tp://www.mysite.com/index.php?route = product / product& product_id = 80

OR

来自:h * tp://www.mysite.com/index.php?route = product / product& path = 63_64_83& product_id = 163 收件人:h * tp://www.mysite.com/index.php?route = product / product& path = 63_64_83& product_id = 175

谢谢:)

2 个答案:

答案 0 :(得分:0)

将此添加到您网络根.htaccess

中的/
RewriteEngine on
RewriteBase /

RewriteCond %{QUERY_STRING} (^|.*?&)product_id=50(&.*|$) [NC]
RewriteRule ^(.*)$ $1?%1product_id=80%2 [R=301,L]

RewriteCond %{QUERY_STRING} (^|.*?&)product_id=163(&.*|$) [NC]
RewriteRule ^(.*)$ $1?%1product_id=175%2 [R=301,L]

答案 1 :(得分:0)

您还可以在seo_url控制器中设置一个很好的开关控件,它将使用Controller类的重定向方法以更原生的方式执行此操作。

打开:

catalog/controller/common/seo_url.php

就在之前:

if (isset($this->request->get['route'])):
    return $this->forward($this->request->get['route']);
endif;

添加:

if (isset($this->request->get['product_id'])):
    switch ($this->request->get['product_id']):
        case 50:
            $this->request->get['product_id'] = 80;
            $redirect = true;
            break;
        case 163:
            $this->request->get['product_id'] = 175;
            $redirect = true;
            break;
    endswitch;
endif;

if (isset($this->request->get['route']) && $redirect):
    $this->redirect($this->request->get['route'], 301);
endif;

没有特别测试,但我有类似的东西来改变一些网址。