If you want static-appearing URLs like www.domain.com/123/, you must modify your script to produce them. Users and search engine spiders will then pick up these static-appearing URLs, and request them from your site.
Then, when your server receives a request for a static URL, your use mod_rewrite to convert that static URL to the dynamic form needed to call your script.
Mod_rewrite works after a request is received by your server, but before any scripts are invoked and before any content is served. Mod_rewrite cannot be used to change the URLs output by your scripts or those present in static html pages. Therefore, the normal use of mod_rewrite may seem "backwards" from what you expected.
See our Apache forum charter for links to Apache and mod_rewrite resources.