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;
}
}
}
?>
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
Hopefully it will now display on screen the error
Code: Select all
error_reporting(E_ALL);
ini_set('display_error',1);
Manually edit the link in your template footer filedony_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.
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.uksitebuilder wrote:Manually edit the link in your template footer filedony_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.
Then in .htaccess add a redirect
Code: Select all
RewriteRule ^manufacturer$ http://www.%{HTTP_HOST}/index.php?route=product/manufacturer [L]
I revert back to my earlier post, we need to see what this error is that is giving you a blank page
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
But cant seem to figured it out for manufacturers
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') ) {
As described here, I added
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!
Code: Select all
if($route == 'common/home') return HTTP_SERVER;
It creates nice clean links to your homepage. the route common/home is gone forever!
Johnathan,
Thank you your post of
Work great for me using 1.5.1.3. Much appreciated!
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]
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;
}
}
}
?>
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
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
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.
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
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;
}
}
}
Thank you for the reply, please tell meragrawal.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".
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
Who is online
Users browsing this forum: Google [Bot] and 75 guests