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:
Server should redirect to:

Once factor to say:
not every pages do append id's.
And So I also provide:
which in turn should redirect to:

or from to

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 as well as in the browser is demonstrated this URL, and internaly, and just internaly, server serve

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]