Page 1 of 2
How can we remove "index.php?route=" from everything
Posted: Tue Nov 27, 2012 12:33 am
by fullphat
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?
Re: How can we remove "index.php?route=" from everything
Posted: Tue Nov 27, 2012 1:15 am
by anung
Re: How can we remove "index.php?route=" from everything
Posted: Tue Nov 27, 2012 8:48 pm
by fullphat
Thanks Anung, I'll give that a whirl now and post the results

Re: How can we remove "index.php?route=" from everything
Posted: Tue Nov 27, 2012 10:48 pm
by fullphat
Unfortunately this didn't work either
Re: How can we remove "index.php?route=" from everything
Posted: Wed Nov 28, 2012 3:55 am
by Johnathan
Re: How can we remove "index.php?route=" from everything
Posted: Wed Nov 28, 2012 5:30 am
by smifis
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;
}
}
}
?>
Re: How can we remove "index.php?route=" from everything
Posted: Wed Nov 28, 2012 5:25 pm
by fullphat
Thanks for the feedback guys, Ill give these a whirl and report back
Re: How can we remove "index.php?route=" from everything
Posted: Wed Nov 28, 2012 10:52 pm
by vaio
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
Re: How can we remove "index.php?route=" from everything
Posted: Wed Nov 28, 2012 10:59 pm
by smifis
in the seo file,
/catalog/ccontroller/common/seo_url.php
and yes it works with the latest version
Re: How can we remove "index.php?route=" from everything
Posted: Wed Nov 28, 2012 11:01 pm
by vaio
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?
Re: How can we remove "index.php?route=" from everything
Posted: Wed Nov 28, 2012 11:17 pm
by smifis
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
Re: How can we remove "index.php?route=" from everything
Posted: Wed Nov 28, 2012 11:38 pm
by vaio
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.
Re: How can we remove "index.php?route=" from everything
Posted: Thu Nov 29, 2012 1:14 am
by smifis
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
Re: How can we remove "index.php?route=" from everything
Posted: Thu Nov 29, 2012 3:23 am
by matte2k
Can you please put the result here as I have the exact same problem....
Thanks!
Re: How can we remove "index.php?route=" from everything
Posted: Thu Nov 29, 2012 3:26 am
by smifis
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;
}
}
}
?>
Re: How can we remove "index.php?route=" from everything
Posted: Thu Nov 29, 2012 3:28 am
by vaio
Too bad there is no THANK YOU button so we can all thank smifis for good work.
Re: How can we remove "index.php?route=" from everything
Posted: Thu Nov 29, 2012 3:30 am
by matte2k
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;
}
}
}
?>
Re: How can we remove "index.php?route=" from everything
Posted: Thu Nov 29, 2012 3:33 am
by smifis
create a backup and then replace the entire contents with what i've posted.
Re: How can we remove "index.php?route=" from everything
Posted: Fri Nov 30, 2012 8:19 pm
by fullphat
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
Re: How can we remove "index.php?route=" from everything
Posted: Sat Dec 01, 2012 2:31 am
by matte2k
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?