With the previous .htaccess configuration, index.php now serves all non-static requests. The script performs a very simple task, it retrieves the filename being requested, get the article and display.
Listing 1: index.php
If the filename is empty, then the request URL must be http://yourdomain.com and this should display your homepage. Otherwise it displays the article by calling display_page() function.
Listing 2: Function to display the page
The function retrieves the article ID from database. If no article matches the filename being requested, it displays a HTTP 404 error. The query string ($_GET) is assigned manually and article.php is loaded. This trick makes article.php 'thinks' it was called with:
http://yourdomain.com/article.php?id=<Article ID>
Put the function above inside index.php. The script is very simple, isn't it?
| 3. Using Apache's mod_rewrite | 5. Results |
| Tel. | +62 31 8662872 +62 856 338 6017 |
| ICQ | 489571630 |
| Skype | dede_bl4ckheart |
| Yahoo | dede_bl4ckheart |
| nashruddin.amin |