You get a bonus - 1 coin for daily activity. Now you have 1 coin

How to remove index.php?route= from all links in OpenCart?

Practice



/* How do I remove index.php?route= from all links in OpenCart?
in the file /catalog/controller/common/seo_url.php
make the following changes (highlighted in bold)
*/
class ControllerCommonSeoUrl extends Controller
{


     //****
    {

        if (isset($this->request->get['product_id']))
        {
            $this->request->get['route'] = 'product/product';
        } elseif (isset($this->request->get['path']))
        {
            $this->request->get['route'] = 'product/category';
        } elseif (isset($this->request->get['manufacturer_id']))
        {
            $this->request->get['route'] = 'product/manufacturer/info';
        } elseif (isset($this->request->get['information_id']))
        {
            $this->request->get['route'] = 'information/information';
        } else
        {
            $this->request->get['route'] = $this->request->get['_route_'];
        }

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

    public function rewrite($link)
    {
        if ($this->config->get('config_seo_url'))
        {
            $url_data = parse_url(str_replace('&', '&', $link));
            $url = '';

            $data = array();

            parse_str($url_data['query'], $data);
            foreach ($data as $key => $value)
            {

                if (isset($data['route']))
                {
                    if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] ==
                        'product/manufacturer/info' || $data['route'] == 'product/product') && $key ==
                        'manufacturer_id') || ($data['route'] == 'information/information' && $key ==
                        'information_id'))
                    {
                        $query = $this->db->query('SELECT * FROM ' . DB_PREFIX .
                            'url_alias WHERE `query` = ' . $this->db->escape($key . '=' . (int)$value));

                        if ($query->num_rows)
                        {
                            $url .= '/' . $query->row['keyword'];

                            unset($data[$key]);
                        }
                    } elseif ($key == 'path')
                    {
                        $categories = explode('_', $value);

                        foreach ($categories as $category)
                        {
                            $query = $this->db->query('SELECT * FROM ' . DB_PREFIX .
                                'url_alias WHERE `query` = 'category_id=' . (int)$category . ');

                            if ($query->num_rows)
                            {
                                $url .= '/' . $query->row['keyword'];
                            }
                        }

                        unset($data[$key]);
                    } else
                    {
                        $query = $this->db->query('SELECT * FROM ' . DB_PREFIX .
                            'url_alias WHERE `query` = '' . $this->db->escape($data['route']) . ');

                        if ($query->num_rows)
                        {
                            $url .= '/' . $query->row['keyword'];

                            unset($data[$key]);
                        }
                    }


                }
            }

            $link = str_replace('index.php?route=', '', $link);


            if ($url)
            {
                unset($data['route']);

                $query = '';

                if ($data)
                {
                    foreach ($data as $key => $value)
                    {
                        $query .= '&' . $key . '=' . $value;
                    }

                    if ($query)
                    {
                        $query = '?' . trim($query, '&');
                    }
                }

                return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ?
                    ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) .
                    $url . $query;
            } else
            {
                return $link;
            }
        } else
        {
            return $link;
        }
    }

   //****

 }

Comments

Guest 14-12-2020
НЕТ ЖИРНОГО
Админ 22-05-2020
на выходных постараюсь, как будет время расписать как для младенцев)
вася 22-05-2020
А по-русски ты уже разучился пояснять?
Timur 21-12-2019
Очень полезная информация

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)