If you need it to display in the browser like http://www.example.com/profile/myuserid then that is the URL you need to link to from the pages of your site.
URLs are defined in links.
Once the request arrives at your server you employ a rewrite using a RewriteRule to fetch the content from the dynamic internal filepath where the content really resides.
A RewriteRule with a domain name in the target delivers a 302 redirect. You need an internal rewrite. Edit your exisitng RewriteRule code to remove the hostname from the target. Add the [L] flag too.
You will also need a redirect for agents requesting the URL in a parameterised format. Use another RewriteRule for this. This prevents duplicate content. This rule will also need to test THE_REQUEST with a preceding RewriteCond. Without this there will be an infinite redirect-rewrite loop.
This redirect + rewrite question is asked many times each month and there are literally thousands of previous threads with example code.