Post by chongshengdz » Tue Oct 14, 2014 10:02 pm

How to rewrite index.php?route to seo friendly urls for opencart 2.0?
for example:
from index.php?route=product/search&search=keyword to search&search=keyword

Electronic Components: integrated circuits, ic, semiconductors, transistors, thyristors, fuses, resistors, diodes, capacitors & more.
buy & sell transistors & mosfet


Active Member

Posts

Joined
Sat Apr 12, 2014 10:18 pm


User avatar
Guru Member

Posts

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

Active Member

Posts

Joined
Sat Apr 12, 2014 10:18 pm


Post by surfdog » Thu Oct 30, 2014 1:22 am

when will this extension be made available for version 2.0? thanks

Newbie

Posts

Joined
Thu Oct 30, 2014 1:21 am

Post by surfdog » Thu Oct 30, 2014 1:23 am

MarketInSG wrote:you can consider this: http://www.opencart.com/index.php?route ... n_id=12422

It's ready for 2.0 use, but we have not publish the update.
when are you going to be publishing this?

Thanks

Newbie

Posts

Joined
Thu Oct 30, 2014 1:21 am

Post by MarketInSG » Sat Nov 01, 2014 4:57 pm

you can drop us a support ticket for you to send the pre released files. We're occupied with updating the last few mods and haven't got time to push the updated mods


User avatar
Guru Member

Posts

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

Post by virgotch » Sat Nov 01, 2014 8:00 pm

you can try to edit this code for 2.0 , this code worked for 1.5
Go to /system/library/url.php and look at the public function link. Replace the function with this version:

Code: Select all

public function link($route, $args = '', $connection = 'NONSSL') {
    if ('NONSSL' == $connection) {
        $url = $this->url;
    } else {
        $url = $this->ssl;  
    }

    if ('common/home' == $route) {
        if ($args) {
            $url .= '?' . str_replace('&', '&', '&' . ltrim($args, '&')); 
        }
    } else {
        $url .= 'index.php?route=' . $route;
        if ($args) {
            $url .= str_replace('&', '&', '&' . ltrim($args, '&')); 
        }
    }

    foreach ($this->rewrite as $rewrite) {
        $url = $rewrite->rewrite($url);
    }

    return $url;
}
run some tests and if the SEO URLs are enabled, it becomes necessary to make one single edit in the /catalog/controller/common/seo_url.php to avoid an "Undefined index" error.

nside public function rewrite, replace this line:

Code: Select all

parse_str($url_info['query'], $data);
With this one:

Code: Select all

if (isset($url_info['query'])) parse_str($url_info['query'], $data);

New member

Posts

Joined
Sun Oct 26, 2014 4:10 am

Post by bonyta2442 » Fri Feb 28, 2020 12:06 am

Thank you for the solution.
I have OC 2.0.1.1 tested the above code:
i have only edit in the /catalog/controller/common/seo_url.php
replacing with:

Code: Select all

if (isset($url_info['query'])) parse_str($url_info['query'], $data);
And the page loads:
https://www.dbkdimitrov.com/search&search=audi

but can't add the rewrite rule like the bottom:

Code: Select all

<file path="catalog/controller/common/seo_url.php">
		<operation>
			<search>
				<![CDATA[
					class ControllerCommonSeoUrl extends Controller {
				]]>
			</search>
			<add position="after">
				<![CDATA[
					private $url_list = array (
						'common/home' => '',
						'account/wishlist' => 'whishlist',
						'account/account' => 'account',
						'account/edit' => 'account/edit',
						'account/password' => 'account/password',
						'account/address' => 'account/address',
						'account/address/edit' => 'account/address/edit',
						'account/reward' => 'account/reward',
						'account/login' => 'account/login',
						'account/logout' => 'account/logout',
						'account/order' => 'account/order',
						'account/order/info' => 'account/order/info',
						'account/newsletter' => 'account/newsletter',
						'account/forgotten' => 'account/forgot',
						'account/download' => 'account/download',
						'account/return' => 'account/return',
						'account/return/add' => 'account/return/add',
						'account/transaction' => 'account/transaction',
						'account/register' => 'account/register',
						'account/recurring' => 'account/recurring',
						'account/voucher' => 'account/voucher',
						'affiliate/account' => 'affiliate',
						'affiliate/edit' => 'affiliate/account',
						'affiliate/password' => 'affiliate/password',
						'affiliate/payment' => 'affiliate/payment',
						'affiliate/tracking' => 'affiliate/tracking',
						'affiliate/transaction' => 'affiliate/transaction',
						'affiliate/logout' => 'affiliate/logout',
						'affiliate/forgotten' => 'affiliate/forgotten',
						'affiliate/register' => 'affiliate/register',
						'affiliate/login' => 'affiliate/login',
						'checkout/cart' => 'cart',
						'checkout/checkout' => 'checkout',
						'checkout/voucher' => 'voucher',
						'checkout/success' => 'success',
						'information/contact' => 'contact',
						'information/ofer' => 'ofer',
						'information/sitemap' => 'sitemap',
						'product/special' => 'special',
						'product/manufacturer' => 'manufacturer',
						'product/compare' => 'compare',
						'product/search' => 'search',
						'product/search&search' => 'search&search', // this doesn't work! please help!
                        
                        
					);
				]]>
			</add>
		</operation>
		<operation>
			<search>
				<![CDATA[
					$this->request->get['route'] = 'error/not_found';
				]]>
			</search>
			<add position="after" offset="4">
				<![CDATA[
					if ( $_s = $this->setURL($this->request->get['_route_']) ) {
						$this->request->get['route'] = $_s;
					}
				]]>
			</add>
		</operation> 
		<operation>
			<search>
				<![CDATA[
					if ($url) {
				]]>
			</search>
			<add position="before" offset="3">
				<![CDATA[
					if( $_u = $this->getURL($data['route']) ){
                        $url .= $_u;
                        unset($data[$key]);
                    }
				]]>
			</add>
		</operation>
		<operation>
			<search>
				<![CDATA[
					return $link;
				]]>
			</search>
			<add position="after" offset="2">
				<![CDATA[
					public function getURL($route) {
							if( count($this->url_list) > 0) {
								 foreach ($this->url_list as $key => $value) {
									if($route == $key) {
										return '/'.$value;
									}
								 }
							}
							return false;
					}
					public function setURL($_route) {
							if( count($this->url_list) > 0 ){
								 foreach ($this->url_list as $key => $value) {
									if($_route == $value) {
										return $key;
									}
								 }
							}
							return false;
					}
				]]>
			</add>
		</operation>
	</file>

https://www.dbkdimitrov.com
https://www.tuningcenterbg.com
https://www.samozamen.com
https://www.h-r.bg


Newbie

Posts

Joined
Sun Aug 19, 2018 12:30 pm

Who is online

Users browsing this forum: No registered users and 32 guests