hello everybody!
I am a mod_rewrite newbie and i am reading some documentation about the topic... I'd like in any case to ask some hints from this community before doing something wrong or stupid...

My application uses urls with a query string of the type:
(The product=... parameter is not always used)

I'd like to use mod_rewrite with the twofold aim of having nice URLs and also of hiding the webstie structure (forbidding for example to access www.site.com/index.php or www.site.com/pics/pic.jpg or avoiding that a wrong url structure is used by users).

The 1st task should be matter of few lines using the RewriteRule directive to get for example


Now if i'd like to have even more nice urls than the previous, like

www.site.com/category/nameOFCategory (hiding in this way the id in DB)

i thought 2 strategies which sound both time wasting...

strategy 1: changing the script which manages the categories so that the htaccess file is updated with new rules every time a category is changed
strategy 2: writing a script which translates name-to-ID on the fly..

I think both strategies would lead to increase the translation times either because the htaccess becomes too big (too many patterns to match) either because the DB has to be queried every time a page is required...

On the other side, strategy 1 would bring an extra advantage: if the pattern doesn't match, we can directly redirect user toward an error page, having an increased robustness for free (in the case of ID i always query the db to check whether such a category/product exist)... This could be also useful to accomplish my 2nd task...

What do you think is the best stragegy? Number 1, number 2 or leave the numeric IDs and query the DB every time? do you know any tutorial for my case?

Concerning the 2nd task: how can one forbid to access a file, e.g. index.php even if this exists, in order to oblige users to use the urls provided by the application?

I thank you since now for every suggestion you'll wish to give me...