Jump to content

[SOLVED] A conceptual question about website and database


thankqwerty

Recommended Posts

Hi, i'm trying to make a website that i can post articles and stuff. I managed to store the articles in my database and displaying them .... etc, which are all fine. At the moment i'm using $GET and php to generate the page with the desired article. The link to any specific article would be something like http://localhost/database/display.php?num=6. Where the articles themselves has no real link. So my questions are:

 

1) how can i make it like the BBC for example, where every page has a link to a real file? (should i create a html file everytime when a new article is posted)

2) if i create a new html file for every new article, what should i store in those files? Since all the information are stored in the database already.

3) is there any downside for what i have at the moment?

You should look into mod_rewrite, which is an Apache module. It enables you to achieve exactly what you're after.

 

It can rewrite http://localhost/database/display/6.html to http://localhost/database/display.php?num=6 "behind the scenes".

The mod_rewrite manual pages do come across as looking harder than it is. If you searched for tutorials on URL rewriting it all becomes a lot more straight forward. You will however need to be able to write (mostly basic) regular expressions. For instance, my previous example is as easy as the following...

#Assuming localhost/database is the webroot
RewriteRule ^display/([0-9]+)\.html$    display.php?num=$1

 

There are a number of advantages, here are a few:

  • Readability
  • Generally quicker to type
  • Easier to convey to people when talking over the phone, for example
  • Search engines used to like them a lot better when spidering - How relevant that is today, I don't know
  • It can add an extra layer of security, for example, in my example above, display.php is expecting nothing but an integer to come through in $_GET['num'], the regular expression ensures that - Though you'll need other rules to prevent passing anything to the original URL

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.