Post by dabigbass » Thu Feb 28, 2008 5:16 am

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?
Last edited by dabigbass on Thu Feb 28, 2008 2:29 pm, edited 1 time in total.

Newbie

Posts

Joined
Thu Feb 28, 2008 5:09 am

Post by fisher318 » Sat Mar 01, 2008 2:11 pm

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 =)

Denver Colorado Web Site Design and Internet Marketing | Tactical Flashlights


New member

Posts

Joined
Tue Feb 26, 2008 5:16 am

Post by dabigbass » Sat Mar 01, 2008 9:54 pm

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.

Newbie

Posts

Joined
Thu Feb 28, 2008 5:09 am

Post by fisher318 » Sun Mar 02, 2008 12:30 am

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

Denver Colorado Web Site Design and Internet Marketing | Tactical Flashlights


New member

Posts

Joined
Tue Feb 26, 2008 5:16 am

Post by fisher318 » Sun Mar 02, 2008 1:48 am

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

Denver Colorado Web Site Design and Internet Marketing | Tactical Flashlights


New member

Posts

Joined
Tue Feb 26, 2008 5:16 am

Post by fisher318 » Sun Mar 02, 2008 2:09 am

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?

Denver Colorado Web Site Design and Internet Marketing | Tactical Flashlights


New member

Posts

Joined
Tue Feb 26, 2008 5:16 am

Post by dabigbass » Sun Mar 02, 2008 6:56 am

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

Newbie

Posts

Joined
Thu Feb 28, 2008 5:09 am

Post by dabigbass » Sun Mar 02, 2008 7:00 am

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=)
Last edited by dabigbass on Sun Mar 02, 2008 7:02 am, edited 1 time in total.

Newbie

Posts

Joined
Thu Feb 28, 2008 5:09 am

Post by fisher318 » Sun Mar 02, 2008 3:12 pm

Awesome my friend!!!  ;D It appears to be working. Do you think it matters whether I name my pages just about, or about.htm to the search engines?

Denver Colorado Web Site Design and Internet Marketing | Tactical Flashlights


New member

Posts

Joined
Tue Feb 26, 2008 5:16 am

Post by dabigbass » Sun Mar 02, 2008 6:22 pm

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.

Newbie

Posts

Joined
Thu Feb 28, 2008 5:09 am

Post by OneBadFlower » Sat Mar 08, 2008 4:07 am

hey do you think this will work in .7.6 as well?

Newbie

Posts

Joined
Mon Aug 27, 2007 8:44 am


Post by dabigbass » Sat Mar 08, 2008 4:49 pm

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

Newbie

Posts

Joined
Thu Feb 28, 2008 5:09 am

Post by hm2k » Tue Mar 11, 2008 10:55 am

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?

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by dabigbass » Tue Mar 11, 2008 7:06 pm

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..

Newbie

Posts

Joined
Thu Feb 28, 2008 5:09 am

Post by hm2k » Tue Mar 11, 2008 8:53 pm

old url, new url? I've only started using opencart recently as of 0.7.7, can you expand on this?

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by dabigbass » Tue Mar 11, 2008 9:23 pm

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.

Newbie

Posts

Joined
Thu Feb 28, 2008 5:09 am

Post by hm2k » Tue Mar 11, 2008 11:24 pm

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.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by anibalin » Thu Mar 27, 2008 3:06 am

@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.

Newbie

Posts

Joined
Sat Mar 22, 2008 11:58 pm

Post by dabigbass » Fri Mar 28, 2008 2:36 pm

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

Newbie

Posts

Joined
Thu Feb 28, 2008 5:09 am
Who is online

Users browsing this forum: No registered users and 9 guests