thankqwerty Posted October 4, 2008 Share Posted October 4, 2008 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? Quote Link to comment Share on other sites More sharing options...
zq29 Posted October 4, 2008 Share Posted October 4, 2008 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". Quote Link to comment Share on other sites More sharing options...
thankqwerty Posted October 4, 2008 Author Share Posted October 4, 2008 Thank you very much for the reply. I'll read through it, though it looks like a bit tough for me at the moment. Would u tell me what is the advantage of doing this (since i see every major sites do it this way)? ??? Quote Link to comment Share on other sites More sharing options...
zq29 Posted October 4, 2008 Share Posted October 4, 2008 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 Quote Link to comment Share on other sites More sharing options...
thankqwerty Posted October 4, 2008 Author Share Posted October 4, 2008 Thanks again, so i guess no new file is created. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.