Post by niagato » Fri Apr 19, 2024 10:33 pm

I'm beginner with Opencart, so I think my question is really common. How I can correctly configure SEO URL links? Let me explain, I configured links for main things like: categories, about us, blog, contacts.

And it works as:
http://sitedomain/categories,
http://sitedomain/about_us,
http://sitedomain/blog,
http://sitedomain/contacts

But when I'm trying to do the same things for http://sitedomain/account -- it doesn't work at all.

Here the example of my SEO URL records:

Code: Select all

Query: account/login
Keyword: account/login

Query: account/logout
Keyword: account/logout
It doesn't work, I get Page Not Found but when I'm changing it to the ->

Code: Select all

Query: account/login
Keyword: login

Query: account/logout
Keyword: logout
It works.

When I'm removing all my manual urls, I have like:
http://sitedomain/index.php?route=account/login

My problem there I want to keep path in the URL:
http://sitedomain/account/login/,
http://sitedomain/account/logout/,
http://sitedomain/account/password/,
etc...

P.S. I'm using standart SEO URL from the box, not the SEO PRO or etc.
Opencart version 3.0.3.9

Newbie

Posts

Joined
Tue Apr 09, 2024 2:09 pm

Post by OSWorX » Sat Apr 20, 2024 3:26 pm

Basically all links which do not come from:
* information
* product
* category

are not SEO-Url ready.
Having such, either add the link and keyword manually into the database or use one of the SEO extensions from the marketplace.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by niagato » Sat Apr 20, 2024 11:16 pm

OSWorX wrote:
Sat Apr 20, 2024 3:26 pm
Basically all links which do not come from:
* information
* product
* category

are not SEO-Url ready.
Having such, either add the link and keyword manually into the database or use one of the SEO extensions from the marketplace.
Hello! Thank you for the reply. Could you please advise some of SEO extension (desirably free :) ) and as alternatively how I can do it manually with database way? Probably I can read some information about it

Many thanks in advance

Newbie

Posts

Joined
Tue Apr 09, 2024 2:09 pm

Post by OSWorX » Sun Apr 21, 2024 12:23 am

Made an extension for urls like that (custom / others / additonally can be added easely also through the extension) by myself a few years ago.
Because of that, it will be a paid extension.

But as it seems, this free extension from the marketplace should do the basics (you asked): https://www.opencart.com/index.php?rout ... n_id=45444

If you need more, simply contact me.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by niagato » Sun Apr 21, 2024 4:44 pm

OSWorX wrote:
Sun Apr 21, 2024 12:23 am
Made an extension for urls like that (custom / others / additonally can be added easely also through the extension) by myself a few years ago.
Because of that, it will be a paid extension.

But as it seems, this free extension from the marketplace should do the basics (you asked): https://www.opencart.com/index.php?rout ... n_id=45444

If you need more, simply contact me.
Hi again! Many thanks for suggestion.

So, now I have all urls like I want (https://domain/account/login) but they redirect me to the Page Not Found. And I'm not sure, is it issue with some backend pathes or with extension...

Do you know how I can check it?

Btw, I don't see any references to the `account` in my seo_url.php file.

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['blogger_id'])) {
		$this->request->get['route'] = 'information/blogger';
	}
		//echo $this->request->get['route'];
}
P.S. I can add the file in its entirety if necessary

Newbie

Posts

Joined
Tue Apr 09, 2024 2:09 pm

Post by nonnedelectari » Sun Apr 21, 2024 9:28 pm

niagato wrote:
Sun Apr 21, 2024 4:44 pm
OSWorX wrote:
Sun Apr 21, 2024 12:23 am
Made an extension for urls like that (custom / others / additonally can be added easely also through the extension) by myself a few years ago.
Because of that, it will be a paid extension.

But as it seems, this free extension from the marketplace should do the basics (you asked): https://www.opencart.com/index.php?rout ... n_id=45444

If you need more, simply contact me.
Hi again! Many thanks for suggestion.

So, now I have all urls like I want (https://domain/account/login) but they redirect me to the Page Not Found. And I'm not sure, is it issue with some backend pathes or with extension...

Do you know how I can check it?

Btw, I don't see any references to the `account` in my seo_url.php file.

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['blogger_id'])) {
		$this->request->get['route'] = 'information/blogger';
	}
		//echo $this->request->get['route'];
}
P.S. I can add the file in its entirety if necessary
It is futile to have seo urls for account or checkout routes as search engines should never visit and certainly not index those urls.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by niagato » Sun Apr 21, 2024 11:09 pm

nonnedelectari wrote:
Sun Apr 21, 2024 9:28 pm
niagato wrote:
Sun Apr 21, 2024 4:44 pm
OSWorX wrote:
Sun Apr 21, 2024 12:23 am
Made an extension for urls like that (custom / others / additonally can be added easely also through the extension) by myself a few years ago.
Because of that, it will be a paid extension.

But as it seems, this free extension from the marketplace should do the basics (you asked): https://www.opencart.com/index.php?rout ... n_id=45444

If you need more, simply contact me.
Hi again! Many thanks for suggestion.

So, now I have all urls like I want (https://domain/account/login) but they redirect me to the Page Not Found. And I'm not sure, is it issue with some backend pathes or with extension...

Do you know how I can check it?

Btw, I don't see any references to the `account` in my seo_url.php file.

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['blogger_id'])) {
		$this->request->get['route'] = 'information/blogger';
	}
		//echo $this->request->get['route'];
}
P.S. I can add the file in its entirety if necessary
It is futile to have seo urls for account or checkout routes as search engines should never visit and certainly not index those urls.
Ahh, I read about it, yeah. So, how I can correctly configure routing for `account` way?

Newbie

Posts

Joined
Tue Apr 09, 2024 2:09 pm

Post by nonnedelectari » Mon Apr 22, 2024 12:26 pm

catalog/controller/startup/seo_url.php

function index.php

change:

Code: Select all


		if (isset($this->request->get['_route_'])) {
			$parts = explode('/', $this->request->get['_route_']);

			// remove any empty arrays from trailing
			if (utf8_strlen(end($parts)) == 0) {
				array_pop($parts);
			}

			foreach ($parts as $part) {
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE keyword = '" . $this->db->escape($part) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");

				if ($query->num_rows) {
					$url = explode('=', $query->row['query']);

					if ($url[0] == 'product_id') {
						$this->request->get['product_id'] = $url[1];
					}

					if ($url[0] == 'category_id') {
						if (!isset($this->request->get['path'])) {
							$this->request->get['path'] = $url[1];
						} else {
							$this->request->get['path'] .= '_' . $url[1];
						}
					}

					if ($url[0] == 'manufacturer_id') {
						$this->request->get['manufacturer_id'] = $url[1];
					}

					if ($url[0] == 'information_id') {
						$this->request->get['information_id'] = $url[1];
					}

					if ($query->row['query'] && $url[0] != 'information_id' && $url[0] != 'manufacturer_id' && $url[0] != 'category_id' && $url[0] != 'product_id') {
						$this->request->get['route'] = $query->row['query'];
					}
				} else {
					$this->request->get['route'] = 'error/not_found';

					break;
				}
			}

			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';
				}
			}
		}
into (change is at the very bottom)

Code: Select all


		if (isset($this->request->get['_route_'])) {
			$parts = explode('/', $this->request->get['_route_']);

			// remove any empty arrays from trailing
			if (utf8_strlen(end($parts)) == 0) {
				array_pop($parts);
			}

			foreach ($parts as $part) {
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE keyword = '" . $this->db->escape($part) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");

				if ($query->num_rows) {
					$url = explode('=', $query->row['query']);

					if ($url[0] == 'product_id') {
						$this->request->get['product_id'] = $url[1];
					}

					if ($url[0] == 'category_id') {
						if (!isset($this->request->get['path'])) {
							$this->request->get['path'] = $url[1];
						} else {
							$this->request->get['path'] .= '_' . $url[1];
						}
					}

					if ($url[0] == 'manufacturer_id') {
						$this->request->get['manufacturer_id'] = $url[1];
					}

					if ($url[0] == 'information_id') {
						$this->request->get['information_id'] = $url[1];
					}

					if ($query->row['query'] && $url[0] != 'information_id' && $url[0] != 'manufacturer_id' && $url[0] != 'category_id' && $url[0] != 'product_id') {
						$this->request->get['route'] = $query->row['query'];
					}
				} else {
					$this->request->get['route'] = 'error/not_found';

					break;
				}
			}

			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 (!empty($this->request->get['route'])) {
			// redirect requested non seo url to seo url if it exists
			$full_link = (!empty($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
			$seo_link = $this->rewrite($full_link);
			if (!stristr($seo_link,'route=')) {
				$this->log->write('redirecting: '.$full_link.' -> '.$seo_link);
				header("Location: $seo_link", true, 301);
				exit;
			}
		}

function rewrite.php

change:

Code: Select all

		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 . "seo_url WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");

					if ($query->num_rows && $query->row['keyword']) {
						$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 . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");

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

							break;
						}
					}
					unset($data[$key]);
				}
			}
		}
into (change at the very bottom):

Code: Select all


		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 . "seo_url WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");

					if ($query->num_rows && $query->row['keyword']) {
						$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 . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");

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

							break;
						}
					}
					unset($data[$key]);
				} elseif ($key == 'route') {
					// no need to query root
					if ($value == 'common/home') {
						$url = '/';
					} else {
						$sql = "SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . $this->config->get('config_language_id') . "'";
						$query = $this->db->query($sql);
						if ($query->num_rows) {
							if ($url != '/') $url .= '/';
							$url .= urlencode(urldecode($query->row['keyword']));
							unset($data[$key]);
						}
					}
				}
			}
		}


then you can basically put any route in the seo url table.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by paulfeakins » Mon Apr 22, 2024 10:48 pm

niagato wrote:
Sat Apr 20, 2024 11:16 pm
Could you please advise some of SEO extension (desirably free :) )
Sometimes it's really best to pay a small amount like $20 for an extension that is maintained and supported.

We keep a list of OpenCart extension developers whose extensions we have tried and tested here:
https://www.antropy.co.uk/blog/good-qua ... xtensions/

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom
Who is online

Users browsing this forum: No registered users and 19 guests