Payday Loan Affiliate Network
Home Sign Up for a Payday Loan Payday Loan Blog
Apply for your payday loan today and get approved for up to $1000.

How Our Program Works
Frequently Asked Questions

Payday Loans
Affiliate Marketing

Add This Blog to your Technorati Favorites
Subscribe to our RSS Feed

Payday Loan Blog - Creating Pretty URLs

 Wednesday, 27 September 2006
....or how to get a blog posting idea only to find randfish just posted about it.

I'm mostly a programmer here and a lot of what I do is internal stuff that wouldn't be directly applicable to anyone else, so finding things to blog about is a little difficult.  But I woke up this morning and thought "hey! I know what I'll blog about - giving dynamic sites static urls".  Imagine my dismay when I starting browsing the blogs I read and found randfish's excellent post about 11 best practices for urls.  Fortunately for me, he's talking more about the form of the urls and not how to create and deal with them.

For most payday loan sites, this isn't going to be an issue.  The vast majority of these sites have very few pages: a home page, an application page, a contact page, and maybe some sort of FAQ.  Four pages, maybe five if your FAQ is really big.  If that's the extent of your site, stop reading now and go create some static pages and be done with it. For such a small number of pages, creating your pages dynamically is overkill.  If you've got more pages - a lot more - read on.

Maybe you want to add some sort of articles to your site - maybe news postings about site updates, or even your own blog.  Eventually, creating those pages statically gets to be a hassle even with Dreamweaver templates and you'll want to move to some sort of dynamic system.  The most common way to do this is to throw the page content in a database and then use php/aspx to pull that data out of the database to fill out a pre-built template.  But how do you tell the system which post to grab?  The easiest way is to pass an ID parameter in the url like  It's easy. It's simple. It's functional.  However, it's neither user nor search engine friendly.  If I hadn't already told you what the url was, what would you think it was about?  I'd say it's probably a blog entry, but that's about all I could tell you.  The next step most people take is to use mod_rewrite to turn the url into something like  That's better insofar as it looks like a static URL to the search engines, but it still suffers from being uninformative. You want something more like  This is a great url.  It doesn't pass any parameters in an obvious manner.  It looks like a static url.  It tells you what the page is about.  It does however have one flaw.  If, at some point in the future, there's another post with the same title, one or the other will never be displayed.  If you're confident you can keep track of all your page names, great. If not, you'll have to add something that makes the post unique.  You could tack the post ID on to the end like 11-url-best-practices-1422.php.  That's unique and has the advantage of making grabbing the post easy, but to the average user, it's just going to be some random number tacked on the end.  Adding the date on the end is another option - 11-url-best-practices-20060927.php.  Most people would probably recognize that as a date.  How you want to go is up to you and what you think will benefit your users more.

Let's assume you've gone with the post ID at the end.   How do you get from url to actual post? In PHP (and I would assume other web scripting languages), there's a variable that contains the uri that was used to request a particular page - $_SERVER['REQUEST_URI'].  It's not much use if all your pages are static (i.e. 1 page = 1 file on your web host), but when your pages are dynamic, it's very useful.  The main trick is to use mod_rewrite to make everything under /blog/ to go through a single script - say blogdetail.php. So blogdetail.php gets called and sees that the uri used was 11-url-best-practices-1422.php.  The first thing I'd do is strip off the .php since it doesn't help us grab the right post.  Then I'd extract the ID number with a regex and put it in its own variable.  After that, remove the post ID from the request uri with another regex.  At this point, you have the ID number and a url-ified version of the page title in their own variables for reasons I'll cover in a little bit.  Now, you'd take the post ID and query your database to grab the post contents and then display it however you want.

So why did I put the page title in a variable too?  It's simple - validation.  You want to be sure that 1 piece of content is only accessible via 1 url.  If all we did was pull the post ID off the end that post would then be accessible via any url that included that ID.  ha-ha-ha-I-want-you-to-have-duplicate-content-issues-in-google-1422.php, and no-really-I-want-to-deindex-your-posts-1422.php would both pull up your posting about the 11 url best practices in addition to the real url of 11-url-best-practices-1422.php.  If some unscrupulous person wanted to, they could use that fact to make Google think you've got a bunch of duplicate pages, which could lead to your page being deindexed.  I'm going to go out on a limb and assume you don't want that.  So what you do is query your database and compare the title you got via the requested uri with the title the page should have based on what's in the database. Grab the title from the db and convert it into the url-ified version - make it all lowercase, replace spaces with dashes and remove any weird characters.  If they match, great, continue on with displaying the page.  If they don't match, you'll want to throw some sort of error like a 404 page not found error.

Hopefully, this has given you some direction on how to create and deal with pretty urls for dynamic sites.  The fewer sites out there with horrific looking urls, the better for all of us.

Jon K.

P.S. Sorry if this was overly long.  I got my degree in philosophy - we're a bit wordy.

Wednesday, 27 September 2006 11:28:34 (US Mountain Standard Time, UTC-07:00)  #     
 |   | 

Call Toll-Free Now! 855-371-8009