Post by meutesouro » Sat Jul 30, 2011 1:29 am

Hi,

I have been able to assign SEO URL's to every other page besides the home page! how do i go about doing this?

Newbie

Posts

Joined
Tue Jul 19, 2011 8:11 pm

Post by uksitebuilder » Sat Jul 30, 2011 3:16 am

insert into database table url_alias

INSERT INTO url_alias (query, keyword) VALUES ('common/home', '');

change url_alis if your tables have a prefix

User avatar
Guru Member

Posts

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

Post by meutesouro » Wed Aug 03, 2011 7:14 pm

this is a pretty noob question but how do i find the database table url_alias file?

Newbie

Posts

Joined
Tue Jul 19, 2011 8:11 pm

Post by uksitebuilder » Wed Aug 03, 2011 7:26 pm

login to your hosting control panel and go in to phpmyadmin

this shold show your database and all tables in it.

url_alias is a table in your database.

it may be called xxxx_url_alias if you have set a prefix to be applied to all table names.

if so edit my INSERT comand to name the url_alias to match your url_alias table name.

User avatar
Guru Member

Posts

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

Post by wolfsteritory » Mon Aug 08, 2011 3:46 pm

hi

i have the same problem

i inserted like this :

Field Value
url_alias_id 1001
query common/home
keyword home

but doesn't work

so im thinking i might be putting the query wrong, ive tried several versions , can somebody give an example ?

User avatar
New member

Posts

Joined
Sun Feb 01, 2009 2:08 am

Post by uksitebuilder » Mon Aug 08, 2011 7:00 pm

Sorry, I forgot to mention that you will also need to edit catalog/controller/common/seo_url.php

Repalce contents with:

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_'])) {
		 $parts = explode('/', $this->request->get['_route_']);

		 $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(count($url) > 1){
			   
			   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{
				  $route = $url[0];
			   }
			} else {
			   $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';
		 }else {
			$this->request->get['route'] = $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 (($key == 'product_id') || ($key == 'manufacturer_id') || ($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]);
			}elseif ($key == 'route') {
			   $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($value) . "'");
			
			   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 . $query;
		 } else {
			return $link;
		 }
	  } else {
		 return $link;
	  }      
   }   
}

User avatar
Guru Member

Posts

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

Post by wolfsteritory » Mon Aug 08, 2011 7:31 pm

thank you

this is for opencart_v1.5.1.1 right ?

User avatar
New member

Posts

Joined
Sun Feb 01, 2009 2:08 am

Post by uksitebuilder » Mon Aug 08, 2011 7:49 pm

works for 1.5.x

User avatar
Guru Member

Posts

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

Post by wolfsteritory » Tue Aug 09, 2011 9:03 pm

doesnt work with language control & chapta , so far this are the bugs ive found

User avatar
New member

Posts

Joined
Sun Feb 01, 2009 2:08 am
Who is online

Users browsing this forum: No registered users and 28 guests