Page 1 of 1

SEO URLs for System Pages

Posted: Wed Sep 28, 2011 12:13 pm
by nachito
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

Re: SEO URLs for System Pages

Posted: Sun Oct 02, 2011 9:02 am
by JAY6390
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...

Re: SEO URLs for System Pages

Posted: Sun Oct 02, 2011 2:04 pm
by gigi30
very nice! thanks for sharing!

Re: SEO URLs for System Pages

Posted: Wed Oct 05, 2011 3:51 pm
by easyaspie
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/

Re: SEO URLs for System Pages

Posted: Wed Oct 05, 2011 10:20 pm
by dony_b
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]);
+                        }
+                    }
 				}
 			}
 		

Re: SEO URLs for System Pages

Posted: Wed Oct 05, 2011 10:29 pm
by Wouterjan
Can it change "index.php?route=common/home" in just "domein.com" ?

Re: SEO URLs for System Pages

Posted: Fri Mar 16, 2012 10:53 am
by JhauraW
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...