Post by smifis » Sat Aug 13, 2011 10:00 am

Hey guys!

First little publicly given mod of opencart 1.5.x from myself, yet to submit it.

What happens is basically, instead of having www.example.com/index.php?route=common/home....etc, it'll take advantage of htrewrite if you have seo turned on. so instead you get www.example.com/common/home.php, or .htm, or .asp, or .jpg (not recommend!)

Granted, it has very little real seo effect on serach engines, but it looks a lot nicer.

You seo keywords will still work is they're set, if there isn't anything set, then it'll be parentcat.php?product_id=xx
Works on cart, account area and check area. works on the information pages too. example.com/information.htm?information_id=xx

Its merely prof of concept at the moment but you can see it working here - I've yet to change the homepage, it's mainly set up so my friend can get used to the admin before we get a 'live' site up with a nice domain. I've also set the page extension to .asp, seemed like a fun thing to do at the time. O0

The Link: http://www.braceletmania.smifis.co.uk/

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by uksitebuilder » Sat Aug 13, 2011 7:30 pm

Already mentioned in the forum a few times on how to achieve this and already an extension available to do this too - see my sig

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by smifis » Sat Aug 13, 2011 10:03 pm

I haven't seen anything mentioned nor have i been able to find any extensions. none of yours offer this basic function standalone.

I'm not asking how to do it, Just asking what people think of it. I'll release it as a free extension when i get round to submitting it.

Do you have an example site for you extension though? some of them look interesting

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by smifis » Sun Aug 14, 2011 1:27 am

*root*/catalog/controller/common/seo.php

Code: Select all

<?php
class ControllerCommonSeoUrl extends Controller {
	public function index() {
		// Add rewrite to url class
		if ($this->config->get('config_seo_url')) {
			$this->url->addRewrite($this);
		}
		
		// Decode URL
		if (isset($this->request->get['_route_'])) {

				$this->request->get['_route_'] = substr($this->request->get['_route_'], 0, -4);
				
			$parts = explode('/', $this->request->get['_route_']);
			
			foreach ($parts as $part) {
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");
				
				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];
					}	
				} else {

					$this->request->get['route']	= $this->request->get['_route_'];
					// $this->request->get['route'] = 'error/not_found';	
				}
			}
			
			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/product';
			} elseif (isset($this->request->get['information_id'])) {
				$this->request->get['route'] = 'information/information';
			}
			
			if (isset($this->request->get['route'])) {
				return $this->forward($this->request->get['route']);
			}
		}
	}
	
	public function rewrite($link) {
		$prefix = '.asp';
		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/product' || $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]);
					}
				}
			}
		
			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 . $prefix . $query;
				// keywords found.
			} else {
				$url_data = parse_url(str_replace('&', '&', $link));
	
				$data = array();
			
				parse_str($url_data['query'], $data);
				
				// $url = '/'.implode('/',array_unique(explode('/',$data['route'])));
				$url = '/' . $data['route'];
				unset($data['route']);
				
				$query = '';
			
				if ($data) {
					foreach ($data as $key => $value) {
						$query .= '&' . $key . '=' . $value;
					}
					
					if ($query) {
						$query = '?' . trim($query, '&');
					}
				}
				
				unset($data);
				
				return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . $url . $prefix . $query;
				
				// return $link; // No seo keywords found in the db.
			}
		} else {
			return $link; //SEO Turned off
		}		
	}	
}
?>

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by uksitebuilder » Sun Aug 14, 2011 2:47 pm

HI Mate,

Just a couple of things

Sitewise Prety URLs

Did you mean Sitewide Pretty URLs ?

Why .asp as the default ? Surely .htm or .html or no extension at all makes more sense ?

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by smifis » Sun Aug 14, 2011 6:47 pm

I figured once a website has been branded and templated, they tend to not look like opencart with a few new colors. having a .asp extension will confuse any potential hacks or con artist trying to break into the system.

And yes, Spelling mistake,

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by alex.lin » Wed Sep 21, 2011 8:59 am

I also have done something like that. and here is my demo site, http://www.uusign.com.

using the category name ,product name as the SEO URL if the SEO keyword is blank when you added or edited them.
also all the link like account/account,common/home rewrite to home, account,ect (could be config).

Opencart Developer

- http://www.cnopencart.com opencart中文站


User avatar
Active Member

Posts

Joined
Thu Jun 03, 2010 12:15 am


Post by shamstr » Wed Sep 21, 2011 8:40 pm

just noticed that the links inside mails are not SEO'ed . Or rather "prettified" :laugh:

is there an easy to change those too?

Newbie

Posts

Joined
Mon Sep 12, 2011 4:50 am

Post by smifis » Fri Sep 23, 2011 5:30 pm

I had not looked into this, I had assumed all of the urls went through the rewrite engine, obviously not however!

I'm quite busy at the moment however I'll have a look when i can find the time. :)

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by annelim » Sun Oct 30, 2011 3:04 am

hi
after i replace the seo url, my page doesnt change any remain the same as url: /product-id14
even i insert keyword in categorise and product data tab, also is a same
how to show it as www.domain.com/computer/HP2002
categorise product name
much appreciate your help

Active Member

Posts

Joined
Fri Oct 28, 2011 5:13 pm

Post by smifis » Sun Oct 30, 2011 3:46 am

if you have a url-alias key set for both the product and category then you will get an url like www.example.com/cat/cat.../prod

if you dont, you will just have www.example.com/prod or example.com/product?product_id=xx

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by SXGuy » Sun Oct 30, 2011 5:09 am

it would be a lot nicer if common/home translated to just domainname.com/

i see no need to use common/home.htm or whatever

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by annelim » Mon Oct 31, 2011 10:36 pm

hi smifis,
sorry for my poor english. could you guide me step by step how to change it
from
example.com/dir/index.php?route=product/product&path=20&product_id=29
to
example.com/dir/hp2000 <- direct link to product name
.
i had done upload all the file into root
what is the next ? go to where modify it?

:-*

Active Member

Posts

Joined
Fri Oct 28, 2011 5:13 pm

Post by smifis » Tue Nov 01, 2011 1:27 am

In the admin interface, for the description for each product there should be a box titled alias_url, this is where you put in hp2000,

my script primarily deal with pages which dont have this filled in so you end up with product.php?product_id=2

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by annelim » Tue Nov 01, 2011 11:11 am

smifis wrote:In the admin interface, for the description for each product there should be a box titled alias_url, this is where you put in hp2000,

my script primarily deal with pages which dont have this filled in so you end up with product.php?product_id=2
hi smifis,
my page only have this but do not have alias_url
1.product name
2.meta tag description
3.meta tag keyword
4.description
5.product tag

where is go wrong??? :'(

Active Member

Posts

Joined
Fri Oct 28, 2011 5:13 pm
Who is online

Users browsing this forum: KhubaibKhan and 299 guests