This post suggest a way to do it:
viewtopic.php?t=150216
Or use an extension:
https://www.opencart.com/index.php?rout ... n_id=30762
A2 Hosting features: Shared Turbo Boost, Managed Warp 1, Unmanaged Hyper 1, and Warp 2 Turbo
the structure of my old URL was https://site.com/index.php?route=produc ... ct_id=1811 and the new one is https://site.com/product-name
so, what I need is redirect all old URL to th the new ones
not manually one by one , but by some solution , I need to bulk redirect all old URLs in the site to the new URLs
https://www.opencart.com/index.php?rout ... 20redirect
https://www.opencart.com/index.php?rout ... 20redirect
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
If you can't find an extension, you could pay a developer such as ourselves or post a job in the Commercial Support Forum.by mona wrote: ↑Thu Jun 10, 2021 11:57 pmHave you checked the marketplace?
https://www.opencart.com/index.php?rout ... 20redirect
https://www.opencart.com/index.php?rout ... 20redirect
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
in file: catalog/controller/product/product.php
after
Code: Select all
public function index() {
Code: Select all
// redirect non-seo to seo if seo enabled and seo url exists
if ($this->config->get('config_seo_url') && strstr($_SERVER['REQUEST_URI'],'product/product')) {
if (!empty($this->request->get['product_id'])) {
if (!empty($this->request->get['path'])) {
$location = $this->url->link('product/product', 'path='.$this->request->get['path'].'&product_id=' . $this->request->get['product_id']);
} else {
$location = $this->url->link('product/product', 'product_id=' . $this->request->get['product_id']);
}
if (!stristr($location,'product/product')) {
header("Location: $location", true, 301);
exit;
}
}
}
If seo is enabled and a product id is given, it creates the seo url.
If the created url is valid, it redirects to that, with or without a category path.
you could do the same for categories.
If you want ALL urls to redirect, you would need a more general solution via the seo_url class.
for all seo urls you can also do this:
in file catalog/controller/startup/seo_url.php
change this:
Code: Select all
if (!isset($this->request->get['route'])) {
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';
}
}
}
to this:
Code: Select all
if (!isset($this->request->get['route'])) {
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';
} elseif (isset($this->request->get['tag'])) {
$this->request->get['route'] = 'product/search';
}
}
} elseif (!empty($this->request->get['route'])) {
// routes we want to check, this avoids doing seo url queries for routes that need no seo urls like account and checkout
$valid_routes = array('product/product', 'product/category', 'product/special', 'product/manufacturer/info', 'information/information'); // extend or limit this to your needs
if (in_array($this->request->get['route'], $valid_routes)) {
$seo_link = $this->rewrite( $_SERVER['REQUEST_URI']);
if (!stristr($seo_link,'route=')) {
$this->log->write('redirecting: '.$_SERVER['REQUEST_URI'].' -> '.$seo_link);
header("Location: $seo_link", true, 301);
exit;
}
}
}
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
This is an Awesome solutionby mona wrote: ↑Fri Jun 11, 2021 8:35 pm
If you want ALL urls to redirect, you would need a more general solution via the seo_url class.
for all seo urls you can also do this:
in file catalog/controller/startup/seo_url.php
change this:
Code: Select all
if (!isset($this->request->get['route'])) { 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'; } } }
to this:
Code: Select all
if (!isset($this->request->get['route'])) { 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'; } elseif (isset($this->request->get['tag'])) { $this->request->get['route'] = 'product/search'; } } } elseif (!empty($this->request->get['route'])) { // routes we want to check, this avoids doing seo url queries for routes that need no seo urls like account and checkout $valid_routes = array('product/product', 'product/category', 'product/special', 'product/manufacturer/info', 'information/information'); // extend or limit this to your needs if (in_array($this->request->get['route'], $valid_routes)) { $seo_link = $this->rewrite( $_SERVER['REQUEST_URI']); if (!stristr($seo_link,'route=')) { $this->log->write('redirecting: '.$_SERVER['REQUEST_URI'].' -> '.$seo_link); header("Location: $seo_link", true, 301); exit; } } }
Thanks a lot by mona
I only found a small problem with it, but I am trying to find it and fix it
The link is redirecting to the following format:
https://DOMAIN.COM/:///CATEGORY/SUB-CATEGORY
But thank you very much
change this:
Code: Select all
$seo_link = $this->rewrite( $_SERVER['REQUEST_URI']);
if (!stristr($seo_link,'route=')) {
$this->log->write('redirecting: '.$_SERVER['REQUEST_URI'].' -> '.$seo_link);
header("Location: $seo_link", true, 301);
exit;
}
Code: Select all
$full_link = (!empty($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; // full url creation
$seo_link = $this->rewrite($full_link); // find the seo url
if (!stristr($seo_link,'route=')) {
$this->log->write('redirecting: '.$full_link.' -> '.$seo_link); // comment this out if all is well, it writes to the log
header("Location: $seo_link", true, 301);
exit;
}
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
Users browsing this forum: No registered users and 460 guests