Wizard
Wizard

Reputation: 11275

Opencart redirect defined routes

I'm have couple of not used routes and searching for solutions to redirect this routes.

For example I have ['common/cart','affiliate/edit' ]

array of routes, and where I can add check to check If route is in this array redirect to 404 ? I think that can be done in /controller/common/seo_url.php ?

Upvotes: 0

Views: 791

Answers (1)

Abdelrhman Adel
Abdelrhman Adel

Reputation: 1187

There are many places where you can add your redirection conditions, the most important thing is avoiding changing the code of core libraries, so I think that the best place would be in index.php

  • Open the file <OC_ROOT>/index.php
  • Search for this code fragment:
if (isset($request->get['route'])) {
    $action = new Action($request->get['route']);
} else {
    $action = new Action('common/home');
}
  • In the isset part, you can check if the variable $request->get['route'] matches any of your obsolete routes and redirect on that basis, for example:
if (isset($request->get['route'])) {
    $ignored_routes = array('common/cart', 'affiliate/edit');
    if(in_array($request->get['route'], $ignored_routes))
        $action = new Action("error/not_found");
    else
        $action = new Action($request->get['route']);
} else {
    $action = new Action('common/home');
}


P.S: Your assumption is wrong, you can't do it in the file /controller/common/seo_url.php, what you want is <OC_ROOT>/system/engine/action.php ;)

Upvotes: 1

Related Questions