Page 1 of 1
URL ALIAS FIXED!
Posted: Thu Feb 28, 2008 5:16 am
by dabigbass
Hey.. I took a stab at fixing the URL Alias problem in Version 0.7.7 and I think I might have found a solution:
In the file:
/library/application/router.php
(make sure you backup router.php in case theres a problem)
if you change the function route(&$request) to have:
Code: Select all
function route(&$request) {
if ($this->path) {
$path = explode('&', $this->path);
for($i=0;$i < sizeof($path);$i++)
{
$route = explode('=',$path[$i]);
$request->set($route[0], $route[1]);
}
}
}
and then try adding aliases in the admin console:
Admin >> Configuration >> URL Alias
example:
URL Query: controller=information&information_id=1
URL Alias: about
it works perfectly!
I tested it with a couple other pages, like categories and subcategories and it works great..
Can others confirm that it works for everything?
Re: URL ALIAS FIXED!
Posted: Sat Mar 01, 2008 2:11 pm
by fisher318
Ok, I changed this:
Code: Select all
function route(&$request) {
if ($this->path) {
$path = explode('/', $this->path);
if (isset($this->routes[$path[0]])) {
$route = explode('/', $this->routes[$path[0]]);
$i = 0;
while ($i < sizeof($path)) {
if (isset($route[$i])) {
$request->set($route[$i], $path[$i]);
} else {
$request->set($path[$i], isset($path[$i+1]) ? $path[$i+1] : NULL);
$i++;
}
$i++;
}
}
}
}
}
?>
Into this:
Code: Select all
function route(&$request) {
if ($this->path) {
$path = explode('&', $this->path);
for($i=0;$i < sizeof($path);$i++)
{
$route = explode('=',$path[$i]);
$request->set($route[0], $route[1]);
}
}
}
?>
And my whole web site went blank, so I switched it back. Did I miss something? My file location was library/application/router.php as per instructed =)
Re: URL ALIAS FIXED!
Posted: Sat Mar 01, 2008 9:54 pm
by dabigbass
If it went blank, then there was probably a PHP error that was produced, most probably some syntax error. Depending on where your site is hosted, they probably have turned off showing the PHP errors..
To override that, you can add this to debug your problem:
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', '1');
at the top of your root index.php file so that it shows exactly what the error is.
Lemme know what you discover.
Re: URL ALIAS FIXED!
Posted: Sun Mar 02, 2008 12:30 am
by fisher318
Ok, thanks, this is the error it came up with
Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /var/www/html/library/application/router.php on line 55
Re: URL ALIAS FIXED!
Posted: Sun Mar 02, 2008 1:48 am
by fisher318
Ok, it looks like it needed one more closing tag. So the final lines of the code should look as follows:
Code: Select all
function route(&$request) {
if ($this->path) {
$path = explode('&', $this->path);
for($i=0;$i < sizeof($path);$i++)
{
$route = explode('=',$path[$i]);
$request->set($route[0], $route[1]);
}
}
}
}
?>
Now I just have to go see if it works =) I'll post back here when I find out
Re: URL ALIAS FIXED!
Posted: Sun Mar 02, 2008 2:09 am
by fisher318
Ok, so now that I got the file installed correctly, I went to the URL alias and put in as follows:
URL Query: controller=information&information_id=1
URL Alias: about
But if you take a look at my
tactical flashlights web site, you will see that by clicking on the bottom left "About Us" link it doesn't seem that my installation of it is working too well. I just get a page cannot be found error. Can you shed any light on the subject?
Re: URL ALIAS FIXED!
Posted: Sun Mar 02, 2008 6:56 am
by dabigbass
Yeah, you're almost there.. the last piece of the puzzle, and the magic that makes it all possible, is the mod_rewrite engine.
Make sure you have a
.htaccess file in the main directory of your opencart folder, with the following lines in it:
Code: Select all
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
Lemme know what happens
Re: URL ALIAS FIXED!
Posted: Sun Mar 02, 2008 7:00 am
by dabigbass
Btw, make sure you remove
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', '1');
from your code if you're no longer in debug mode; you don't want a bunch of jargon displayed to the common user if there's ever an error=)
Re: URL ALIAS FIXED!
Posted: Sun Mar 02, 2008 3:12 pm
by fisher318
Awesome my friend!!!

It appears to be working. Do you think it matters whether I name my pages just about, or about.htm to the search engines?
Re: URL ALIAS FIXED!
Posted: Sun Mar 02, 2008 6:22 pm
by dabigbass
That's good to hear=) About whether to append .htm to the end of your URL's..
I personally prefer the cleanest URL possible, so I never like to show any extensions at all.. I don't think
search engines really toss a fit either.. they definitely do like cleaner URL's over long dynamic ones though.
Re: URL ALIAS FIXED!
Posted: Sat Mar 08, 2008 4:07 am
by OneBadFlower
hey do you think this will work in .7.6 as well?
Re: URL ALIAS FIXED!
Posted: Sat Mar 08, 2008 4:49 pm
by dabigbass
i would assume it would..although i don't particularly know what was upgraded from 7.6 to 7.7..
but its a quick fix, it just requires replacing one function.. if that doesn't work, reverting back isn't hard
although if you try it and it doesn't work, you could try upgrading to 7.7 altogether..unless of course you've made tons of mods to your 7.6
Re: URL ALIAS FIXED!
Posted: Tue Mar 11, 2008 10:55 am
by hm2k
dabigbass wrote:
Hey.. I took a stab at fixing the URL Alias problem in Version 0.7.7 and I think I might have found a solution:
In the file:
/library/application/router.php
(make sure you backup router.php in case theres a problem)
if you change the function route(&$request) to have:
Code: Select all
function route(&$request) {
if ($this->path) {
$path = explode('&', $this->path);
for($i=0;$i < sizeof($path);$i++)
{
$route = explode('=',$path[$i]);
$request->set($route[0], $route[1]);
}
}
}
and then try adding aliases in the admin console:
Admin >> Configuration >> URL Alias
example:
URL Query: controller=information&information_id=1
URL Alias: about
it works perfectly!
I tested it with a couple other pages, like categories and subcategories and it works great..
Can others confirm that it works for everything?
Excuse my ignorance but what is this code actually meant to do vs the existing one?
Re: URL ALIAS FIXED!
Posted: Tue Mar 11, 2008 7:06 pm
by dabigbass
The best way to explain it is..
Suppose you want to make an address like:
yoursite.com/index.php?controller=product&product_id=9
become
yoursite.com/shirt
the old code was trying to map an *old* URL that had a bunch of slashes (/) in it, to your new, clean URL.
it was saying, "split the URL into strings wherever you find a '/' and assign whatever is in between to variables.
only problem though was that the old URL didn't have slashes, it had a query that broke up the data by ampersands (&) and equal signs (=)
so the new code split the URL between the "&" signs, then assigned the variables to whatever it was "=" to.
hope that made sense..
Re: URL ALIAS FIXED!
Posted: Tue Mar 11, 2008 8:53 pm
by hm2k
old url, new url? I've only started using opencart recently as of 0.7.7, can you expand on this?
Re: URL ALIAS FIXED!
Posted: Tue Mar 11, 2008 9:23 pm
by dabigbass
in my previous post:
yoursite.com/index.php?controller=product&product_id=9
is the "old url" or the messy url that we wanna make look clean.
the new url would be:
yoursite.com/shirt
which is an alias, or mask of the old url, above.
Re: URL ALIAS FIXED!
Posted: Tue Mar 11, 2008 11:24 pm
by hm2k
Oh I see, the original code simply didn't work.
Can I recommend changing
$request->set($route[0], $route[1]);
to:
if (!empty($route[0]) && !empty($route[1])) $request->set($route[0], $route[1]);
This will stop an error i've seen from happening.
Re: URL ALIAS FIXED!
Posted: Thu Mar 27, 2008 3:06 am
by anibalin
@dabigbass, thanks for your time. I would like to ask you this:
mi site is showed up in this url:
http://www.mysite.com/public_html/
if i go to:
http://www.mysite.com I get "work in progress page type".
the site files are like this:
http://www.imgdash.com/uploads/9c29dbce0e..JPG
and in the public_html
http://www.imgdash.com/uploads/6ce2eff190..JPG
opencart site.
So, in url alias I set this:
Url Query: mysite.com
URL Alias: mysite.com/public_html
In theory it should work. Right?
Thanks again.
Re: URL ALIAS FIXED!
Posted: Fri Mar 28, 2008 2:36 pm
by dabigbass
the problem with that setup is that your opencart system, in its entirety, resides in the /public_html/ folder, which means that if you are accessing something outside of that folder, there is nothing that would bind the user to your opencart.
while you can use a .htaccess folder in your root directory to handle this, the best thing for you to do is set the public_html folder as your default, root directory for your webserver, so that
www.mysite.com takes you directly to the opencart application.
lemme know if that makes sense,
thanks