代码之家  ›  专栏  ›  技术社区  ›  Akila Wickramasekara

htaccess URL重写以设置无SEO URL

  •  1
  • Akila Wickramasekara  · 技术社区  · 7 年前

    我需要向opencart中的无seo url发送请求。

    前任: https://xxxxxxx.yyy.zz/index.php?search=apple <--第一个Url

    这将不会加载搜索页面 但是noe SEO url将加载如下所示的搜索页面

    https://xxxxxxx.yyy.zz/index.php?route=product/search&search=apple
    

    <--第二个Url

    如何将第一个Url重定向到第二个Url?

    1 回复  |  直到 7 年前
        1
  •  0
  •   DigitCart    7 年前

    如果您想通过php和OpenCart框架完成此操作,可以通过以下方式完成:

    在里面 catalog\controller\common\header.php

    查找:

    public function index() {
    

    在其后面添加:

    // Get url parameters
    $get = $this->request->get;
    
    // Get current route
    $route = isset($get['route']) ? $get['route'] : '';
    
    // If the Search parameter is available in the url, but the current page is not the search page
    if(isset($get['search']) && $route != 'product/search'){
        // Redirect user to the search page with search keyword
        $this->response->redirect($this->url->link('product/search', 'search=' . $this->request->get['search'], true));
    }