Post by nachito » Wed Sep 28, 2011 12:13 pm

I love that I'm able to create custom SEO-friendly URLs for products, categories, manufacturers, information pages... but I hate that I've still got to use http://example.com/index.php?route=checkout/cart, instead of something simpler like http://example.com/cart. So, I fixed it. (At least for version 1.5.0...)

http://stackoverflow.com/q/7578055/961455

Apply the patch and add to the existing url_alias table

Code: Select all

INSERT INTO `url_alias` (`url_alias_id`, `query`, `keyword`) VALUES (NULL, 'checkout/cart', 'cart');
http://example.com/index.php?route=checkout/cart now becomes http://example.com/cart

Attachments

Patch to catalog/controller/common/seo_url.php


Newbie

Posts

Joined
Wed Sep 28, 2011 12:00 pm

Post by JAY6390 » Sun Oct 02, 2011 9:02 am

Nice. I have a mod that I have built privately mostly for fun that will do what you want, and in fact let you change any URL to any other, without the need of editing databases or even using the url alias table :) I'll have to clean it up and get it available for purchase in the extension store...

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by gigi30 » Sun Oct 02, 2011 2:04 pm

very nice! thanks for sharing!

Newbie

Posts

Joined
Sun Sep 11, 2011 2:12 pm

Post by easyaspie » Wed Oct 05, 2011 3:51 pm

To be sure that it works with and without a tailing slash (shop.com/cart and shop.com/cart/) I've added a str_replace("/", "", **) to the two selects:

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . str_replace("/", "", $this->db->escape($this->request->get['_route_'])) . "'");

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . str_replace("/", "", $this->db->escape($data['route'])) . "'");


There may be a smarter way, but i works :)

The tailing slash is importent on some pages for SEO:
http://www.ragepank.com/articles/68/tha ... es-matter/

Newbie

Posts

Joined
Wed Oct 05, 2011 3:45 pm

Post by dony_b » Wed Oct 05, 2011 10:20 pm

So where exactly do you add the code to seo_url.php :

Code: Select all

Index: catalog/controller/common/seo_url.php
===================================================================
--- catalog/controller/common/seo_url.php	(old)
+++ catalog/controller/common/seo_url.php	(new)
@@ -18,23 +18,17 @@
 					
 					if ($url[0] == 'product_id') {
 						$this->request->get['product_id'] = $url[1];
-					}
-					
-					if ($url[0] == 'category_id') {
+					} elseif ($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') {
+					} elseif ($url[0] == 'manufacturer_id') {
 						$this->request->get['manufacturer_id'] = $url[1];
+					} elseif ($url[0] == 'information_id') {
+						$this->request->get['information_id'] = $url[1];
 					}
-					
-					if ($url[0] == 'information_id') {
-						$this->request->get['information_id'] = $url[1];
-					}	
 				} else {
 					$this->request->get['route'] = 'error/not_found';	
 				}
@@ -48,7 +42,12 @@
 				$this->request->get['route'] = 'product/manufacturer/product';
 			} elseif (isset($this->request->get['information_id'])) {
 				$this->request->get['route'] = 'information/information';
-			}
+			} else {
+                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($this->request->get['_route_']) . "'");
+                if ($query->num_rows) {
+                    $this->request->get['route'] = $query->row['query'];
+                }
+            }
 			
 			if (isset($this->request->get['route'])) {
 				return $this->forward($this->request->get['route']);
@@ -88,7 +87,15 @@
 						}
 						
 						unset($data[$key]);
-					}
+					} else {
+                        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($data['route']) . "'");
+
+                        if ($query->num_rows) {
+                            $url .= '/' . $query->row['keyword'];
+
+                            unset($data[$key]);
+                        }
+                    }
 				}
 			}
 		

User avatar
Active Member

Posts

Joined
Wed Aug 18, 2010 9:56 pm
Location - Boston, MA

Post by Wouterjan » Wed Oct 05, 2011 10:29 pm

Can it change "index.php?route=common/home" in just "domein.com" ?

1.5.0


Active Member

Posts

Joined
Sat Jun 04, 2011 9:46 pm

Post by JhauraW » Fri Mar 16, 2012 10:53 am

I patched the file and added most of the key aliases to the DB. Here they are to make it easier for somebody:

1. Backup your orig seo_url.php file.
2. FTP over the patched version attached here.
3. Backup your url_alias DB table.
4. Add these aliases to the DB:

Code: Select all

INSERT INTO `url_alias` (`url_alias_id`, `query`, `keyword`) VALUES
(NULL, 'common/home', ''),

(NULL, 'checkout/cart', 'cart'),
(NULL, 'checkout/checkout', 'checkout'),

(NULL, 'account/account', 'myaccount'),
(NULL, 'account/login', 'login'),
(NULL, 'account/forgotten', 'forgot'),
(NULL, 'account/register', 'register'),

(NULL, 'account/order', 'order-history'),
(NULL, 'account/return', 'returns'),
(NULL, 'account/transaction', 'transactions'),
(NULL, 'account/voucher', 'gift-voucher'),

(NULL, 'account/wishlist', 'wishlist'),
(NULL, 'account/download', 'downloads'),
(NULL, 'account/newsletter', 'newsletter'),

(NULL, 'product/search', 'search'),
(NULL, 'product/special', 'specials'),
(NULL, 'product/manufacturer', 'brands'),

(NULL, 'affiliate/account', 'affiliates'),
(NULL, 'information/sitemap', 'sitemap');
Hope this helps somebody...

Attachments

Patched seo url file:
/catalog/controller/common/seo_url.php


Newbie

Posts

Joined
Fri Mar 16, 2012 10:47 am
Who is online

Users browsing this forum: No registered users and 128 guests