Post by dony_b » Tue Sep 20, 2011 11:15 pm

I tried that and checked the error log file from the admin and it doesn't show anything

Is there something else I can try ?

User avatar
Active Member

Posts

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

Post by dony_b » Tue Sep 20, 2011 11:17 pm

Below is the file :

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
Active Member

Posts

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

Post by dony_b » Tue Sep 20, 2011 11:22 pm

My goal for this is to only change the index.php?route=product/manufacturer to manufacturer if there is another way of doing this I open to that.

User avatar
Active Member

Posts

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

Post by uksitebuilder » Tue Sep 20, 2011 11:23 pm

Make sure your gzip compression is off in admin, then pop the following at the top of the index.php file just after the opening php tag

Code: Select all

error_reporting(E_ALL);
ini_set('display_error',1);
Hopefully it will now display on screen the error

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

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

Post by uksitebuilder » Tue Sep 20, 2011 11:26 pm

dony_b wrote:My goal for this is to only change the index.php?route=product/manufacturer to manufacturer if there is another way of doing this I open to that.
Manually edit the link in your template footer file

Then in .htaccess add a redirect

Code: Select all

RewriteRule ^manufacturer$ http://www.%{HTTP_HOST}/index.php?route=product/manufacturer [L]

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

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

Post by dony_b » Tue Sep 20, 2011 11:29 pm

uksitebuilder wrote:
dony_b wrote:My goal for this is to only change the index.php?route=product/manufacturer to manufacturer if there is another way of doing this I open to that.
Manually edit the link in your template footer file

Then in .htaccess add a redirect

Code: Select all

RewriteRule ^manufacturer$ http://www.%{HTTP_HOST}/index.php?route=product/manufacturer [L]
The only thing with that is that it doesn't change the URL structure but it only redirects it.

User avatar
Active Member

Posts

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

Post by dony_b » Tue Sep 20, 2011 11:46 pm

that didnt work as it goes back to the homepage.

Your post I just saw a second ago got deleted ???

User avatar
Active Member

Posts

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

Post by uksitebuilder » Wed Sep 21, 2011 12:10 am

I revert back to my earlier post, we need to see what this error is that is giving you a blank page

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

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

Post by dony_b » Wed Sep 21, 2011 1:43 am

What is exactly that you change in seo_url.php that makes it work ? Maybe I can try that one.

I removed the common/home occurrences by adding this code to seo_url.php

Code: Select all

 $url || (isset($data['route']) && $data['route'] == 'common/home') ) { 
But cant seem to figured it out for manufacturers

User avatar
Active Member

Posts

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

Post by uksitebuilder » Wed Sep 21, 2011 1:49 am

here's a vqmod with the changes in it.

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

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

Post by dony_b » Wed Sep 21, 2011 1:57 am

It messes up the seo_url.php

User avatar
Active Member

Posts

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

Post by fgd007 » Tue Nov 08, 2011 8:51 am

As described here, I added

Code: Select all

if($route == 'common/home') return HTTP_SERVER;
in the system/library/url.php file and it worked like a charm!

It creates nice clean links to your homepage. the route common/home is gone forever!

Newbie

Posts

Joined
Sun Nov 06, 2011 4:37 am

Post by jw00dy » Thu Nov 17, 2011 3:39 pm

would you mind posting your url.php file contents?

Or at least specify where you put that line of code.

Newbie

Posts

Joined
Thu Nov 17, 2011 3:37 pm

Post by MrZimm » Mon Mar 12, 2012 4:20 am

Johnathan,

Thank you your post of

Code: Select all

RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteRule ^index\.php$ http://adultdiaperscanada.ca? [R=301,L]  
Work great for me using 1.5.1.3. Much appreciated!

New member

Posts

Joined
Mon Feb 27, 2012 11:20 pm

Post by scanreg » Tue Apr 17, 2012 8:55 pm

Does anyone know if this would affect google search engine rankings?

Thanks

Active Member

Posts

Joined
Thu May 06, 2010 12:15 am

Post by Kanyin » Wed May 01, 2013 12:58 am

Currently working on my site but I'm not much of a coder: Replace system/library/url.php code with what is below

Code: Select all

<?php
class Url {
	private $url;
	private $ssl;
	private $rewrite = array();
	
	public function __construct($url, $ssl = '') {
		$this->url = $url;
		$this->ssl = $ssl;
	}
		
	public function addRewrite($rewrite) {
		$this->rewrite[] = $rewrite;
	}
		
	public function link($route, $args = '', $connection = 'NONSSL') {
		if($route == 'common/home') {
                     return HTTP_SERVER;
	       } else {
		if ($connection ==  'NONSSL') {
			$url = $this->url;
		} else {
			$url = $this->ssl;	
		}
		
		$url .= 'index.php?route=' . $route;
			
		if ($args) {
			$url .= str_replace('&', '&', '&' . ltrim($args, '&')); 
		}
		
		foreach ($this->rewrite as $rewrite) {
			$url = $rewrite->rewrite($url);
		}
				
		return $url;
	        }
       }
}
?>

New member

Posts

Joined
Tue Mar 12, 2013 2:14 am

Post by Jhewell0508 » Sat Jan 18, 2014 11:07 am

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteRule ^index\.php$ http://www.example.com? [R=301,L]

I was able to get mine to work with this code
replace your website name "www.example.com

Newbie

Posts

Joined
Fri Jan 17, 2014 10:35 am

Post by sunsys » Thu Mar 05, 2015 10:10 am

Can somebody help me for one issue, I have changed the seo url links as per the method described in the pages here(and by following uksb's "url_alias" method and Johnathan script for .htaccess file) and my site was working very well. I had personally checked every seo url link to see it was resolving correctly.

But today suddenly the "sitemap" link from the footer is not giving the store map, I am getting an error "The page you requested cannot be found!". I checked in the phpmyadmin and the url link is proper (information/sitemap--->sitemap) and also in the layout it is correct "information/sitemap". The fun part is that when I give the link as "domain.com/information/sitemap" then the page opens correctly.

Can someone please point me in the right direction or tell me what the issue is. I am no programmer but I have learnt from these forums.

Thank You.

Edit: when I turn off the seo url in admin then the sitemap resolves correctly, please help me set this right.

Regards,
Sun Systems
Industrial Electronics and Instrumentation


User avatar
Active Member

Posts

Joined
Tue Jan 27, 2015 5:19 am

Post by ragrawal.in » Mon Mar 30, 2015 6:44 pm

Please replace your seo_url.php with the following code. It is a generalized solution which removes "index.php?route" and give you neater seo url. It will change "/index.php?route=common/home" to "/common/home" and "/index.php?route=account/(.*)" to "/account/$1" .

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_']);

			// remove any empty arrays from trailing
			if (utf8_strlen(end($parts)) == 0) {
				array_pop($parts);
			}
			
			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 ($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];
					}
					
					if ($query->row['query'] && $url[0] != 'information_id' && $url[0] != 'manufacturer_id' && $url[0] != 'category_id' && $url[0] != 'product_id') {
						$this->request->get['route'] = $query->row['query'];
					}
				} elseif($part=='account' || $part=='common'){
					$this->request->get['route']= $this->request->get['_route_'];
					break;
				}else {
					$this->request->get['route'] = 'error/not_found';

					break;
				}
			}

			if (!isset($this->request->get['route'])) {
				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/info';
				} elseif (isset($this->request->get['information_id'])) {
					
					$this->request->get['route'] = 'information/information';
				}
			}

			if (isset($this->request->get['route'])) {
				return new Action($this->request->get['route']);
			}
		}
	}

	public function rewrite($link) {
		$url_info = parse_url(str_replace('&', '&', $link));
		
		$url = '';

		$data = array();

		parse_str($url_info['query'], $data);
		
		foreach ($data as $key => $value) {
			if (isset($data['route'])) {
			
				if ((($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $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 && $query->row['keyword']) {
						$url .= '/' . $query->row['keyword'];

						unset($data[$key]);
					}
					//echo $url."<br>";
				} 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 && $query->row['keyword']) {
							$url .= '/' . $query->row['keyword'];
						} else {
							$url = '';
							break;
						}
					
					}

					unset($data[$key]);
				}elseif($key=="route" && preg_match("/^(account|common)/",$value)){
					$url .= '/'.$value; 
				}
			}
		}

		if ($url) {
			unset($data['route']);

			$query = '';

			if ($data) {
				foreach ($data as $key => $value) {
					$query .= '&' . rawurlencode((string)$key) . '=' . rawurlencode((string)$value);
				}

				if ($query) {
					$query = '?' . str_replace('&', '&', trim($query, '&'));
				}
			}
			
			return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;
		} else {
			return $link;
		}
	}
}

Newbie

Posts

Joined
Mon Mar 30, 2015 6:35 pm

Post by sunsys » Fri Apr 03, 2015 12:43 am

ragrawal.in wrote:Please replace your seo_url.php with the following code. It is a generalized solution which removes "index.php?route" and give you neater seo url. It will change "/index.php?route=common/home" to "/common/home" and "/index.php?route=account/(.*)" to "/account/$1".
Thank you for the reply, please tell me
1. Should I remove everything from the original file and replace with your code ? and

2. what will happen if I do the change as you have suggested because I have already changed all the urls to "mysite.com/category/product" format, now there is no more index.php? anywhere, also I have enabled the seo url option in admin and done the necessary changes to .htaccess file so all that is fine. If there is anything that should do or something else that I have missed out on or overlooked please advice.

The only odd thing is the sitemap thing as described before, I have no clue as to why it should STOP working after 2 months, that is surprising.

Regards,
Sun Systems
Industrial Electronics and Instrumentation


User avatar
Active Member

Posts

Joined
Tue Jan 27, 2015 5:19 am
Who is online

Users browsing this forum: Baidu [Spider] and 65 guests