Because the title states, I want a quite complex url rewrite mechanism for any web-application as .htaccess rule. I have looked quite a bit now and attempted hundred of various rewrite rules.

So, essentially this is exactly what I want:
User would go to: http://www.site.com/product.php?id=12
Server should redirect to: http://site.com/product/12

Once factor to say:
not every pages do append id's.
And So I also provide: http://www.site.com/some/page.php
which in turn should redirect to: http://site.com/some/page

or from http://site.com/anotherone.php to http://site.com/anotherone

You assistance is much appreciated and thank you plenty ahead of time for you personally help!

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)\.php$ http://%1/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)\.php\?id=([0-9]+)$ http://%1/$1/$2 [R=301,L]

I supose that you simply, formerly have this mod_rewrite rule active:

Customers would go to http://site.com/product/12 as well as in the browser is demonstrated this URL, and internaly, and just internaly, server serve http://www.site.com/product.php?id=12

Place the first RewriteCond and Rule this:

   RewriteCond %{ENV:REDIRECT_STATUS} !200
   RewriteRule ^(\w+)\.php\?id=(\d*)$ /$1/$2 [R=301]

And add another to get rid of the .php when finishes with .php

   RewriteCond %{ENV:REDIRECT_STATUS} !200
   RewriteRule ^(\w+)\.php$ /$1 [R=301]