How can I create friendly URLs for my site?


So far I include everything in index.php:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]

There are also pages where I use $_GET like this:

SELECT * FROM news WHERE id = ".intval($_GET['id'])

If I want to view a news I type news?id=1 instead of ?page=news&id=1 but I want to be able to use news/1.

Will I have to add a rewrite rule for every page where I use GET? Or is there a better way?

I hope I don't have to do this for all my pages.

this single rule should allow both with and without ids (and also makes the slashes optional):

RewriteRule ^([^/]*)(/([^/]*)/?)?$ index.php?page=$1&id=$3 [QSA,L]

if you don't want to allow / and //, change the *'s to +'s