I have a .htaccess file where when a user signs up on my site, they'll be redirected to example.com/profiles/[username] . The ugly URL is example.com/profiles/?username=john where john can be any name. Whenever, the user searches for let's say example.com/profiles/[username] a 404 gets displayed, so instead I want this friendly URL to redirect to an ugly one so their profile can be displayed. So I want example.com/profiles/john to be redirected to example.com/profiles/?username=john internally.
Here's my .htaccess conditions:
RewriteCond %{THE_REQUEST} /profiles/\?username=([^&\s]+) [NC]
RewriteRule ^ /profiles/%1? [L,R=302]
RewriteRule ^profiles/([\w-]+)/?$ /profiles/?username=$1 [L]
These conditions successfully remove the ?username=john part of the URL, how do I make it so it's the other way around? So when someone searches for example.com/profiles/john it gets redirected to example.com/profiles/?username=john internally so the page gets successfully displayed?