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
Newbie question - how can I do this simple task?
Moderator: General Moderators
-
conquesimo
- Forum Newbie
- Posts: 10
- Joined: Mon May 26, 2008 3:30 pm
-
whiterabbit
- Forum Newbie
- Posts: 14
- Joined: Thu May 22, 2008 6:58 pm
Re: Newbie question - how can I do this simple task?
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:
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.
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]http://www.ilovejackdaniels.com/mod_rew ... _sheet.pdf
Hope this helps.
-
conquesimo
- Forum Newbie
- Posts: 10
- Joined: Mon May 26, 2008 3:30 pm
Re: Newbie question - how can I do this simple task?
Excellent. This is exactly what I needed. Thanks, whiterabbitwhiterabbit wrote:In order to do this, you have to use a mod rewrite rule.