Community Forums

how to SEO the index.php?route=common/home

General support for technical problems with OpenCart v1.x

Re: how to SEO the index.php?route=common/home

Postby uksitebuilder » Mon Jul 11, 2011 4:39 pm

Why not simply add it to the url_alias database table ?

In ours we have added this and also made many other pages SEO Friendly URLs

for home page:

INSERT INTO url_alias (query, keyword) VALUES ('common/home', '');
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

Re: how to SEO the index.php?route=common/home

Postby Johnathan » Tue Jul 12, 2011 7:48 am

uksitebuilder wrote:Why not simply add it to the url_alias database table ?

In ours we have added this and also made many other pages SEO Friendly URLs

for home page:

INSERT INTO url_alias (query, keyword) VALUES ('common/home', '');

Because that doesn't work. The code that processes the SEO URLs only accounts for products, categories, manufacturers, and information pages. You must have modified your seo_url.php files that database addition works for you.
Image
ImageImageImageImageImageImageImageImageImage
User avatar
Johnathan
Global Moderator
 
Posts: 2955
Joined: Thu Dec 17, 2009 7:08 pm

Re: how to SEO the index.php?route=common/home

Postby uksitebuilder » Tue Jul 12, 2011 7:54 am

Of course you are correct, I had a totally blank moment when I posted the above.

To solve, I have attached a rewritten catalog/controller/common/seo_url.php file

seo_url.php
(3.86 KiB) Downloaded 243 times
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

Re: how to SEO the index.php?route=common/home

Postby tonic » Tue Jul 12, 2011 10:25 am

uksitebuilder wrote:Of course you are correct, I had a totally blank moment when I posted the above.

To solve, I have attached a rewritten catalog/controller/common/seo_url.php file

seo_url.php

Yep, but in this file there is a line at the top of file:
Code: Select all
$this->url->addRewrite($this);

which is returns fatal error, because there are no this method in standart OC code. What this method do and this is mandatory for good working SEO URL rewriting?

If you may - can you put here the file with this method & class.
Thx.
tonic
 
Posts: 1
Joined: Tue Jul 12, 2011 10:22 am

Re: how to SEO the index.php?route=common/home

Postby uksitebuilder » Tue Jul 12, 2011 10:47 am

It's in system/library/url.php (OC 1.5.x)

See my mods below for a mod that does all the site Friendly SEO
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

Re: how to SEO the index.php?route=common/home

Postby yest » Wed Aug 24, 2011 8:20 pm

i replaced the file but there is no changed ... why ???
yest
 
Posts: 80
Joined: Wed Aug 04, 2010 5:57 pm

Re: how to SEO the index.php?route=common/home

Postby dony_b » Tue Sep 20, 2011 2:57 pm

uksitebuilder wrote:Of course you are correct, I had a totally blank moment when I posted the above.

To solve, I have attached a rewritten catalog/controller/common/seo_url.php file

seo_url.php



This works with v1.5.0.5 but not with v1.5.1

I've done it it in the phpmyadmin but the seo_url.php file seems to be different in 1.5.1

Whats the difference to apply ?
User avatar
dony_b
 
Posts: 233
Joined: Wed Aug 18, 2010 1:56 pm
Location: Boston, MA

Re: how to SEO the index.php?route=common/home

Postby uksitebuilder » Tue Sep 20, 2011 3:00 pm

It works fine in 1.5.1 I have it running on my demo store: http://www.designs.org.uk which is default OC 1.5.1.2
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

Re: how to SEO the index.php?route=common/home

Postby dony_b » Tue Sep 20, 2011 3:09 pm

I get a blank page when I change the seo_url.php

why is this you think ?
User avatar
dony_b
 
Posts: 233
Joined: Wed Aug 18, 2010 1:56 pm
Location: Boston, MA

Re: how to SEO the index.php?route=common/home

Postby uksitebuilder » Tue Sep 20, 2011 3:11 pm

Usually means some kind of php fatal error or possibly whitespace being injected either before th opening php tag or after the closing php tag.

Do your error logs give an indication ?

If you have compression turned on in your admin settings, turn it off for a moment and it may display on screen what the actual error is.
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

Re: how to SEO the index.php?route=common/home

Postby dony_b » Tue Sep 20, 2011 3: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
dony_b
 
Posts: 233
Joined: Wed Aug 18, 2010 1:56 pm
Location: Boston, MA

Re: how to SEO the index.php?route=common/home

Postby dony_b » Tue Sep 20, 2011 3: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('&amp;', '&', $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
dony_b
 
Posts: 233
Joined: Wed Aug 18, 2010 1:56 pm
Location: Boston, MA

Re: how to SEO the index.php?route=common/home

Postby dony_b » Tue Sep 20, 2011 3: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
dony_b
 
Posts: 233
Joined: Wed Aug 18, 2010 1:56 pm
Location: Boston, MA

Re: how to SEO the index.php?route=common/home

Postby uksitebuilder » Tue Sep 20, 2011 3: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
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

Re: how to SEO the index.php?route=common/home

Postby uksitebuilder » Tue Sep 20, 2011 3: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]
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

Re: how to SEO the index.php?route=common/home

Postby dony_b » Tue Sep 20, 2011 3: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
dony_b
 
Posts: 233
Joined: Wed Aug 18, 2010 1:56 pm
Location: Boston, MA

Re: how to SEO the index.php?route=common/home

Postby dony_b » Tue Sep 20, 2011 3:46 pm

that didnt work as it goes back to the homepage.

Your post I just saw a second ago got deleted ???
User avatar
dony_b
 
Posts: 233
Joined: Wed Aug 18, 2010 1:56 pm
Location: Boston, MA

Re: how to SEO the index.php?route=common/home

Postby uksitebuilder » Tue Sep 20, 2011 4:10 pm

I revert back to my earlier post, we need to see what this error is that is giving you a blank page
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

Re: how to SEO the index.php?route=common/home

Postby dony_b » Tue Sep 20, 2011 5:43 pm

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
dony_b
 
Posts: 233
Joined: Wed Aug 18, 2010 1:56 pm
Location: Boston, MA

Re: how to SEO the index.php?route=common/home

Postby uksitebuilder » Tue Sep 20, 2011 5:49 pm

here's a vqmod with the changes in it.

seo_url.xml
(1.89 KiB) Downloaded 173 times
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

PreviousNext

Return to General Support

Who is online

Users browsing this forum: anung, Bing [Bot], Cleo, kimcorcoran, MWB-02, raymondization, yeagerd and 49 guests

Hosted by Arvixe Web Hosting