Page 1 of 1

Newbie question - how can I do this simple task?

Posted: Mon May 26, 2008 3:34 pm
by conquesimo
I'm creating my first website and trying to teach myself how to use PHP and mySQL in order to do it. The design of the site essentially boils down to a journal with many journal entries, similar to a blog. I want the title of each entry to be present in the URL, and I'm thinking it will look something like these:

http://www.mywebsite.com/journal/0001/introduction
http://www.mywebsite.com/journal/0002/the_journey_begins
http://www.mywebsite.com/journal/0003/yeehaw_its_an_adventure

I want to have these URLs while at the same time have them all refer to a single PHP file that will populate itself with the corresponding content from a database. In this way, I can update the layout of every journal page by just modifying a single file. Does that make sense?

In all likelihood, I'm probably going about this all wrong. Any pointers, solutions or suggestions are most welcome. I'm a newb... I know... but I have to start somewhere.

Thanks,
ConQuesimo

Re: Newbie question - how can I do this simple task?

Posted: Mon May 26, 2008 5:50 pm
by whiterabbit
http://www.mywebsite.com/journal/0001/introduction

For the above URL, I am going to assume that 0001 is the ID of the article in the database and introduction is the title of the journal.

In order to do this, you have to use a mod rewrite rule. Create a .htaccess file in your web root and add the following lines:

Code: Select all

RewriteEngine on
RewriteRule ^journal/([0-9]+)/([a-zA-Z0-9]+) journal.php?journal_id=$1&journal_title=$2 [L]
Look up mod rewrite in google and for a great quick reference check out this link:
http://www.ilovejackdaniels.com/mod_rew ... _sheet.pdf

Hope this helps.

Re: Newbie question - how can I do this simple task?

Posted: Mon May 26, 2008 6:09 pm
by conquesimo
whiterabbit wrote:In order to do this, you have to use a mod rewrite rule.
Excellent. This is exactly what I needed. Thanks, whiterabbit :-)