Pretty Urls

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
evans123
Forum Newbie
Posts: 18
Joined: Wed Nov 17, 2010 4:48 pm

Pretty Urls

Post by evans123 »

How would i go about creating a pretty url script? Ive looked on the net for some example code and can't seem to find much.
User avatar
Zyxist
Forum Contributor
Posts: 104
Joined: Sun Jan 14, 2007 10:44 am
Location: Cracow, Poland

Re: Pretty Urls

Post by Zyxist »

The first thing you need is mod_rewrite or similar server extension that would allow you to avoid file names in the URL address. The second thing is a router. It's a component that performs a translation:

* URL address -> request argument list
* argument list -> URL address

Routers usually contain some URL patterns, so that they know which pieces of the address should be mapped to what arguments.
evans123
Forum Newbie
Posts: 18
Joined: Wed Nov 17, 2010 4:48 pm

Re: Pretty Urls

Post by evans123 »

I have created my permalink script/structure now.

/Directory/Category/Sub Category/

When trying to edit say individual users should i use a permalink like /members/edit/username or use the old fashioned way of $_GET from the url?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Pretty Urls

Post by Jonah Bron »

What do you mean "old fashioned"? That's how you get data from the url rewrite.

http://www.google.com/search?q=mod_rewrite+tutorial
evans123
Forum Newbie
Posts: 18
Joined: Wed Nov 17, 2010 4:48 pm

Re: Pretty Urls

Post by evans123 »

Yeah but would it be better to use /edit/username or ?edit=username, for example.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Pretty Urls

Post by Jonah Bron »

Yeah. That's what url rewriting is for. It takes a URL like this (for example):

http://example.com/edit/joe

And maps it to (say) this:

http://example.com/edit.php?username=joe
Post Reply