Search Engines Friendly links...

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
NTGr
Forum Newbie
Posts: 14
Joined: Fri Mar 30, 2007 11:28 am

Search Engines Friendly links...

Post by NTGr »

Hello.
I m trying to understand what is the best way to build my links..
Any Help ???

So far i m building my links this way...
For my HomePage... http://localhost/index.php?p=homebody
For the categories...http://localhost/index.php?p=display&cid=1
and for the items....
http://localhost/index.php?p=display&ci ... =EuroDance VINYL AristName ArtistSong

What you think???
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Those would be consider non-search engine friendly links is what I think :)

However, most search engines now do spider those links, I am still in the boat that believes dynamic-looking links still rank lower than static-looking links.

http://www.domain.com/articleid/10

http://www.domainc.com/index.php?articleid=10

The first is what would be considered a "clean" url the latter is what is considered a non search friendly URL
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Remember that the only interface is not just the GUI (the page). The URL is actually part of the interface too and making it friendlier for end users makes your overall apllication easier to use. Users can make educated guesses on how to modify the variables in the URL. Users will feel more comfortable changing what looks like a path, compared with changing something with a load of ? & = in it.

EDIT | For some research points look at mod_rewrite and the Front Controller design pattern with a request router.
NTGr
Forum Newbie
Posts: 14
Joined: Fri Mar 30, 2007 11:28 am

Thnx....

Post by NTGr »

Thnx..
IF i uderstand correctly i sould use mode_rewrite to RECREATE the LINKS ....RIGHT???

This will effect the way my pages work?? since cid & pid are values used by several functions

Thnx again....
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Thnx....

Post by Chris Corbyn »

NTGr wrote:Thnx..
IF i uderstand correctly i sould use mode_rewrite to RECREATE the LINKS ....RIGHT???

This will effect the way my pages work?? since cid & pid are values used by several functions

Thnx again....
mod_rewrite takes a URL like http://localhost/foo/bar/x/y and transparently turns it into the correct form http://localhost?foo=bar&x=y for example. You define those rules. If you have hard-coded links into your application which point to the & ? = form of the URL then you'll have to recode all those to be friendly links. It's good practise to "build" all URLs in your application with a function you create, such as create_url($path). For example rather than hard-coding:

Code: Select all

<a href="?module=checkout&action=confirm&order=1234">Confirm your order</a>
Do this:

Code: Select all

<a href="<?php echo create_url("/checkout/confirm?order=1234") ?>">Confirm your order</a>
That function then needs to understand the string you're passing it in order to make the friendly URL. Here I assume that there will always be a /module/action part in the URL. You could make the function easier to write by passing 3 arguments $module, $action, $args. You can slo have the function lookup rules defined in your routing configuration. See below.

mod_rewrite can be used to play a fairly minor part in friendly URLs. If you can set up mod_rewrite to simply prepend index.php/ then you get URIs like /some/friendly/url mapped to something like:

/index.php/some/friendly/url

You can then break that down in your own code and work out where to direct the request. Using the approach allows you to change your routing rules without changing your web server configuration. Any helper functions for building friendly URLs in your application can now be a bit more flexible/dynamic too.
NTGr
Forum Newbie
Posts: 14
Joined: Fri Mar 30, 2007 11:28 am

Post by NTGr »

It's good practise to "build" all URLs in your application with a function you create, such as create_url($path). For example rather than hard-coding:
Can you pls give me a HINT how this function must be ???
OR
some links(tutorials) to read more about ??

Thnx Once again.....
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

There's a class I built for making clean URLs in the "code snippets" forum.
NTGr
Forum Newbie
Posts: 14
Joined: Fri Mar 30, 2007 11:28 am

Thnx..scottayy

Post by NTGr »

Thnx scottayy.....
:D 8)
Post Reply