Page 1 of 1

Removing route for clean URL

Posted: Thu Mar 04, 2010 1:18 am
by yadakhov
Hi all,

I'm new to opencart. Great app by the way. Very easy to install and a nice codebase.

I'm having problem with the clean URL.

What I have done already:
1. make sure mod_rewrite is on on my webserver
2. rename .htaccess.txt to .htaccess
3. enabling SEO url in admin

I don't like address like this:
http://www.example.com/index.php?route=account/login

I want address like this:
http://www.example.com/account/login

Re: Removing route for clean URL

Posted: Sat Mar 06, 2010 7:50 pm
by wgn_white
So do I.
Are there any solution for this at the moment?

Re: Removing route for clean URL

Posted: Sat Mar 06, 2010 9:28 pm
by Qphoria
All the steps taken are all that is needed. The only other step would be if your store is in a subdirectory like "shop" then you need to change your RewriteBase to /shop/. Otherwise it might be that your server doesn't support mod rewrite

Re: Removing route for clean URL

Posted: Sun Mar 07, 2010 8:13 pm
by wgn_white
Qphoria wrote:All the steps taken are all that is needed. The only other step would be if your store is in a subdirectory like "shop" then you need to change your RewriteBase to /shop/. Otherwise it might be that your server doesn't support mod rewrite
Other information like privacy policy is working.
But would it be nice for all url to have a nice url?

Re: Removing route for clean URL

Posted: Sun Mar 07, 2010 11:32 pm
by MulderDSM
I have a question on this topic also. Once I made the changes the pages work correctly, but the url doesn't have any ".html" on the end of it and looks a little unfinished.

For example, this is how my URL shows up now:
http://www.thinkdifferentdesigns.com/st ... %20Capitol

but it would look more complete if it looked like this:
http://www.thinkdifferentdesigns.com/st ... pitol.html

Is there any way to add .html to end of the urls?

Re: Removing route for clean URL

Posted: Mon Mar 08, 2010 12:53 am
by rph
I haven't fully tested it but this seems to work.

/catalog/model/tool/seo_url.php

Code: Select all

return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query;
to

Code: Select all

return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query . (strstr($query, '?') ? '' : '.html');

/.htaccess

Code: Select all

RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]
to

Code: Select all

RewriteRule ^(.*)\?*(\.html)$ index.php?_route_=$1 [L,QSA]
EDIT2: Cleaned up the code. Now works with SEO URL and regular URLs in default store.

Re: Removing route for clean URL

Posted: Mon Mar 08, 2010 7:33 am
by MulderDSM
Ryan, thanks, but when using these two mod's I was getting 404 errors, so I changed it back.

Re: Removing route for clean URL

Posted: Mon Mar 08, 2010 4:47 pm
by rph
You could just cheat and add .html to the end of all your product SEO URLs. You just won't be able to do it for your categories. You really should also remove the space in your SEO URLs and switch them to all lower case.

EDIT: Updated code above works on default store install.

Re: Removing route for clean URL

Posted: Thu Jun 03, 2010 8:01 am
by cevarief
It's wierd that special route like /account/cart, /account/login doesn't work. The seo url only work for routing product, category, info and manufacturing which has alias in the database.
I had to hack the CommonSEOUrl file to make it work by comparing with predifined array ($special_route).

Code: Select all

$parts = explode('/', $this->request->get['_route_']);
$special_route = array('common','information','account','checkout','shipping','product');
if(in_array($parts[0], $special_route) && count($parts) == 2) //must be 2 !
                    return $this->forward(join('/', $parts));
If the url is like http://localhost/opencart/account/login or /product/special, the code will check if the first split of the route is in $special_route and return it as route=account/login, otherwise it will be processed normally.

Re: Removing route for clean URL

Posted: Fri Jul 02, 2010 7:52 am
by qahar
i just want to give suggest on troubleshoot like this, you should mention what version you use. so it's can help another to learn and keep them to not posting the samething on same version OC

Re: Removing route for clean URL

Posted: Tue Jun 11, 2013 10:47 am
by tylerdperez
The solution above didn't work 100% with 1.5.5.1, here is what I did to make it work.

.htaccess from this:

Code: Select all

RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]
.htaccess to this:

Code: Select all

RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]
public_html/catalog/controller/common/seo_url.php from this:

Code: Select all

return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;

public_html/catalog/controller/common/seo_url.php to this:

Code: Select all

return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query . '.html';

Re: Removing route for clean URL

Posted: Tue Jun 11, 2013 8:54 pm
by Qphoria
tylerdperez wrote:The solution above didn't work 100% with 1.5.5.1, here is what I did to make it work.

.htaccess from this:

Code: Select all

RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]
.htaccess to this:

Code: Select all

RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]
Maybe I'm missing it, but these 2 look identical

Re: Removing route for clean URL

Posted: Sat Mar 01, 2014 11:28 pm
by Whyamiy
Sorry for bringing up an old thread, but I've found myself in a similar situation where adding the .html suffix to each url would save me having to set up any redirects. Every single url is identical on both websites except my old one finishes .html and the new one doesn't.

The solution from rph is working perfectly for this, however it has broken the pagination. Clicking on page 2, 3 etc brings a 404 not found error. Does anyone know how to fix this please?