Post by fullphat » Tue Nov 27, 2012 12:33 am

Lets face it, "index.php?route=" is ugly.

How do we, on the latest version of opencart, remove it from being seen.

I've gone through htaccess, changing the seo_url.php tried modules, both paid and free, and i'm STILL having issues, with the cart page, all the links that are dynamic ie <?php echo contact(); ?> etc.

Does anyone have any solution that really does solve this issue?

User avatar
New member

Posts

Joined
Wed Oct 19, 2011 4:47 pm

Post by anung » Tue Nov 27, 2012 1:15 am


User avatar
Active Member

Posts

Joined
Fri Mar 30, 2012 10:32 am
Location - Indonesia

Post by fullphat » Tue Nov 27, 2012 8:48 pm

Thanks Anung, I'll give that a whirl now and post the results :)

User avatar
New member

Posts

Joined
Wed Oct 19, 2011 4:47 pm

Post by fullphat » Tue Nov 27, 2012 10:48 pm

Unfortunately this didn't work either

User avatar
New member

Posts

Joined
Wed Oct 19, 2011 4:47 pm

Post by Johnathan » Wed Nov 28, 2012 3:55 am


Image
Image Image Image Image


User avatar
Global Moderator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by smifis » Wed Nov 28, 2012 5:30 am

I have my own script which i use on the sites I make.

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_'])) {
			$parts2 = explode('.php', $this->request->get['_route_']);
			//$parts = explode('/', $this->request->get['_route_']);
			$parts = explode('/', $parts2[0]);
			foreach ($parts as $part) {
			$part = rtrim($part,'.php');
				$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];
					}	
				} else {
					$this->request->get['route'] = 'error/not_found';	
				}
			}
			//print_r($parts2[1]);
			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';
			} else {
				$this->request->get['route'] = $parts2[0];
			/*
				$parts = explode('/', $this->request->get['_route_']);
				$this->request->get['route'] = $parts[0] . '/' . rtrim($parts[1],'.php');
				unset($parts[0]);
				unset($parts[1]);
				$nextpara = '';
				foreach( $parts as $key => $value ) {
					if( 0 === $key%2) { //Even
						$nextpara = $value;
					}
					else {
						$this->request->get[$nextpara] = $value;
					}
				}*/
				
			}
			if (isset($parts2[1])) {
				$par = explode('/',$parts2[1]);
				unset($par[0]);
				
				$par = array_values($par);
				
				$nextpara = '';
				foreach( $par as $key => $value ) {
					if( 0 === $key%2) { //Even
						$nextpara = $value;
					}
					else {
						$this->request->get[$nextpara] = $value;
					}
				}
			}
			
			if (isset($this->request->get['route'])) {
				return $this->forward($this->request->get['route']);
			}
		} elseif(isset($this->request->get['route'])){
			if ($this->request->get['route'] =='product/search') {
				$pageURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
				if ($_SERVER["SERVER_PORT"] != "80")
				{
					$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
				} 
				else 
				{
					$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
				}
				$this->redirect($this->rewrite($pageURL));
			}
		}
	}
	
	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 (isset($data['route'])) {
					if (($data['route'] == 'product/product' && $key == 'product_id') || (($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) {
							$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]);
					}
				}
			}
		
			if ($url) {
				unset($data['route']);
			
				$query = '';
			/*
				if ($data) {
					foreach ($data as $key => $value) {
						$query .= '&' . $key . '=' . $value;
					}
					
					if ($query) {
						$query = '?' . trim($query, '&');
					}
				}*/
				
				if(count($data)> 0) {
					//$url .= '/';
				
					foreach ($data as $key => $value) {
						$query .= '/'.$key.'/'.$value; 
					}
				}

				return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . '.php'. $query;
			} else {
			//	echo 'no seo url for '.$link.'<br />';
				
				$url_data = parse_url(str_replace('&', '&', $link));
		
				$url = '/'; 
				
				$data = array();
				
				parse_str($url_data['query'], $data);
			//print_r($data);
			
				$url .= $data['route'] . '.php';
				unset($data['route']);
				
				if(count($data)> 0) {
					//$url .= '/';
				
					foreach ($data as $key => $value) {
						$url .= '/'.$key.'/'.$value;
					}
				}
				//echo $url;
				return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url;
				//return $link;
			}
		} else {
			return $link;
		}		
	}	
}
?>

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by fullphat » Wed Nov 28, 2012 5:25 pm

Thanks for the feedback guys, Ill give these a whirl and report back

User avatar
New member

Posts

Joined
Wed Oct 19, 2011 4:47 pm

Post by vaio » Wed Nov 28, 2012 10:52 pm

smifis wrote:I have my own script which i use on the sites I make...
Hello dear smifis,
where did you put this code? In Seo-url file?
Do you use it on latest OC 1.5.4.1?

I get this error:
Parse error: syntax error, unexpected T_ELSE in .../vqmod/vqcache/vq2-catalog_controller_common_seo_url.php on line 60.
Thank you for clarification,
Vaio

Newbie

Posts

Joined
Thu Mar 03, 2011 12:51 am

Post by smifis » Wed Nov 28, 2012 10:59 pm

in the seo file,

/catalog/ccontroller/common/seo_url.php

and yes it works with the latest version

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by vaio » Wed Nov 28, 2012 11:01 pm

Hey smifis,
i have tried, but so far no luck.

i have changed seo_url.php and emptied vqcache, but get error as shown above and here again:

Parse error: syntax error, unexpected T_ELSE in .../vqmod/vqcache/vq2-catalog_controller_common_seo_url.php on line 60.

Do you use vQmod on your OC?

Newbie

Posts

Joined
Thu Mar 03, 2011 12:51 am

Post by smifis » Wed Nov 28, 2012 11:17 pm

I do but it looks like one of the vqmods is effecting the seo urls.

could you disable all of you vqmods for me and see if it works? if it does then enables each one individually until you find the culprit, tell me what it is, and i'll find a fix or a workaround for you

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by vaio » Wed Nov 28, 2012 11:38 pm

Hello smifis,
apparentlyGenerate SEO keyword vQmod and seo_url.php are not really compatible.

If you manage to find where/why they are not compatible, this would be really great, since Generator is really good for great SEO address.

Also another question, is it possible to:
1. make Home button go just on domain url: domain.tld/ instead of domain.tld/common/home.php, i believe it is nicer + more useful for SEO
2. hide above category from common links (account, information, common): /account/account.php -> just to show /account.php
3. i experience 'problem' with product categories: /desktops became /desktops.php/path/20

Thank you for your kind help,
V.

Newbie

Posts

Joined
Thu Mar 03, 2011 12:51 am

Post by smifis » Thu Nov 29, 2012 1:14 am

could you pm me a copy of the extension for me?

I'll get these done, I will have some more time tonight and send you a new script.

Thanks

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by matte2k » Thu Nov 29, 2012 3:23 am

Can you please put the result here as I have the exact same problem....
Thanks!

Active Member

Posts

Joined
Thu Mar 01, 2012 7:07 pm

Post by smifis » Thu Nov 29, 2012 3:26 am

We have just finished a new 'fixed' version.

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_'])) {
         $parts2 = explode('.php', $this->request->get['_route_']);
		 
         $parts = explode('/', $parts2[0]);
         foreach ($parts as $part) {
         $part = rtrim($part,'.php');
            $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];
               }   
            } 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/info';
         } elseif (isset($this->request->get['information_id'])) {
            $this->request->get['route'] = 'information/information';
         } 
		if (isset($this->request->get['route'])) {
            $this->request->get['route'] = $parts2[0];
         }
         if (isset($parts2[1])) {
            $par = explode('/',$parts2[1]);
            unset($par[0]);
            
            $par = array_values($par);
            
            $nextpara = '';
            foreach( $par as $key => $value ) {
               if( 0 === $key%2) { //Even
                  $nextpara = $value;
               }
               else {
                  $this->request->get[$nextpara] = $value;
               }
            }
         }
         
         if (isset($this->request->get['route'])) {
            return $this->forward($this->request->get['route']);
         }
      } elseif(isset($this->request->get['route'])){
         if ($this->request->get['route'] =='product/search') {
            $pageURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
            if ($_SERVER["SERVER_PORT"] != "80")
            {
               $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
            } 
            else 
            {
               $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
            }
            $this->redirect($this->rewrite($pageURL));
         }
      }
   }
   
   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 (isset($data['route'])) {
               if (($data['route'] == 'product/product' && $key == 'product_id') || (($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) {
                     $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]);
               }
            }
         }
      
         if ($url) {
            unset($data['route']);
         
            $query = '';
            
            if(count($data)> 0) {
            
               foreach ($data as $key => $value) {
                  $query .= '/'.$key.'/'.$value; 
               }
            }

            return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . '.php'. $query;
         } else {
            
            $url_data = parse_url(str_replace('&', '&', $link));
      
            $url = '/'; 
            
            $data = array();
            
            parse_str($url_data['query'], $data);
			
         
            $url .= $data['route'] . '.php';
            unset($data['route']);
            
            if(count($data)> 0) {
			
            
               foreach ($data as $key => $value) {
                  $url .= '/'.$key.'/'.$value;
               }
            }
			
            return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url;
         }
      } else {
         return $link;
      }      
   }   
}
?>

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by vaio » Thu Nov 29, 2012 3:28 am

Too bad there is no THANK YOU button so we can all thank smifis for good work.

Newbie

Posts

Joined
Thu Mar 03, 2011 12:51 am

Post by matte2k » Thu Nov 29, 2012 3:30 am

Were do i put this exactly?.. My sep_url looks like this:

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_']);
			
			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];
					}	
				} 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';
			}
			
			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 (isset($data['route'])) {
					if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/product' || $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) {
							$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]);
					}
				}
			}
		
			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;
		}		
	}	
}
?>

Active Member

Posts

Joined
Thu Mar 01, 2012 7:07 pm

Post by smifis » Thu Nov 29, 2012 3:33 am

create a backup and then replace the entire contents with what i've posted.

Active Member

Posts

Joined
Sat Jan 15, 2011 10:37 pm


Post by fullphat » Fri Nov 30, 2012 8:19 pm

Hi guys,

Just to update everyone, I got this working with the generous help from Anung off the forum who provided me with the attached file which goes in vqmod/xml

This fixed all my URL's to be search engine friendly

Thanks again for the help,
Martin

Attachments


User avatar
New member

Posts

Joined
Wed Oct 19, 2011 4:47 pm

Post by matte2k » Sat Dec 01, 2012 2:31 am

Thanks... seams to work nice...

But on a search. The URL still is: http://seriersant.se/index.php?route=pr ... e=Julalbum

If I want to change the name on for example "/contact" to better fit my language, like "/kontakt"
Were do I do this?

Active Member

Posts

Joined
Thu Mar 01, 2012 7:07 pm
Who is online

Users browsing this forum: No registered users and 105 guests