How you implement the URL rewriting depends on what you're trying to do, what platform you're running on, what server-side scripting and CMS you might be using, whether you already have dynamic URLs "in the wild" that you want to now convert to search engine friendly URLs, etc.
It may very well be that Mod_Rewrite/.htaccess is NOT the best way to implement it. Yes it has robust URL rewriting capabilities... But if every page on your site is rendered via a CMS using for example an index.php in your root folder, you might want to modify index.php so that it does the URL rewriting for you.
When someone requests a SEF URL, the index.php could ask the CMS what id is associated with that SEF URL... and then URL rewrite the request to
http://www.example.com/index.php?p=XXX where XXX is the id returned for the corresponding page. This is the way WordPress and other CMSs typically handle it.
To do this in Mod_Rewrite, you'll either have to maintail URL rewriting rules for every page in your system OR write an rewrite rule that uses a MapFile in HTML to lookup the corresponding ID for each SEF URL.
Also, if your dynamic URLs are already out their "in the wild", you'll need to implement 301 redirects.
For example, if you current use
http://www.example.com/index.php?p=139 to refer to some page but you want it to be
http://www.example.com/sef-page-name.html then you might implement something like the following in the .htaccess in the root folder of your web:
# if request /index.php?p=139 or /?p=139 then 301 redirect to /sef-page-name.html
RewriteCond $1 ^(index\.php)?$ [NC]
RewriteCond %{QUERY_STRING} ^p=139$
RewriteRule (.*)
http://www.example.com/sef-page-name.html [R=301,L]
# if request is for the SEF URL URL rewrite to the dynamic
RewriteCond $1 ^sef-page-name.html$ [NC]
RewriteRule (.*)
http://www.example.com/index.php?p=139 [L]
This way if someone requests the old dynamic URL directly, your server 301 redirects them to the corresponding new search engine friendly URL. When their browser makes the 2nd request this time for the search engine friendly URL, the server (in the same roundtrip) will display the page. The browser will still show the search engine friendly URL while behind the scenes the server is actually serving the page at /index.php?p=139.
Hope that helps.