Post by erodriguez » Thu Apr 14, 2016 10:30 pm

Hi guys, im very happy with Opencart becouse it so easy and i can extends his functionality writting my own code.

The first thing I wanted to do with Opencart was modfy current routing system.

By default look at
myamazingwebsite.com/index.php?route=account/login

I changes this for
myamazingwebsite.com/account/login
Look more friendly

Ok, here we go ..

Go to "system/library/url.php"
Replace link function for

Code: Select all

public function link($route, $args = '', $secure = false) {
        $url = ($this->ssl && $secure ? 'https://' : 'http://') 
             . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/index.php?route=' . $route;
		
		if ($args) {
			if (is_array($args)) {
				$url .= '&' . http_build_query($args);
			} else {
				$url .= str_replace('&', '&', '&' . ltrim($args, '&'));
			}
		}

		foreach ($this->rewrite as $rewrite) {
			$url = $rewrite->rewrite($url);
		}
        
        // Remove route in URL
        if(!strpos($url, '/admin')) {
            $url = str_replace('/index.php?route=', '/', $url);
        }            

		return $url;
	}
Go to catalog/controller/startup/seo_url.php
Find

Code: Select all

$this->request->get['route'] = 'error/not_found';
Replace with

Code: Select all

$this->request->get['route'] = $this->request->get['_route_'];
When the route is wrong, opencart trow 404 error page.

This changes only create friendly url for your front-office, for back-office (admin area) not.
Dont forget Enabled Seo Url from your admin panel and add .httaccess

Please give me your feedback ..
Last edited by erodriguez on Fri Apr 15, 2016 12:02 am, edited 2 times in total.

Newbie

Posts

Joined
Thu Apr 14, 2016 9:45 pm

Post by villagedefrance » Thu Apr 14, 2016 11:24 pm

Interesting but I don't really see the point when all "information" pages can be Seo_rewritten anyway.

By default you get the same result without modifying anything.

I guess it could be useful for some other pages ::)

OpenCart custom solutions @ https://villagedefrance.net


User avatar
Active Member

Posts

Joined
Wed Oct 13, 2010 10:35 pm
Location - UK

Post by erodriguez » Fri Apr 15, 2016 12:00 am

Im new with Opencart ..

My contribution modify all urls that not use Seo Keyword .. like
index.php?route=account/login to account/login

Newbie

Posts

Joined
Thu Apr 14, 2016 9:45 pm

Post by chidangit » Thu Oct 27, 2016 12:34 pm

Hi @erodriguez,
Thank you verry much for your code.

But index.php?route still on search page, any ideal for remove it.

Newbie

Posts

Joined
Thu Oct 27, 2016 12:29 pm

User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore
Who is online

Users browsing this forum: Bing [Bot] and 31 guests