Say there were specific URLs on your other pages that you could check, the following should help.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-_]*)$ /profile.php?user=$1 [L]
This helps maintain current URLs by allowing users to use shortcuts. In addition, it RewriteRulewill only match URLs that do not contain /, which will help protect against unwanted redirects. In this way,
/i-am-a-user -> MATCHES
/i_am_a_user -> MATCHES
/i-!am-a-user -> NOT MATCHED
/i.am.a.user -> NOT MATCHED
/i.am.a.user/ -> NOT MATCHED
/some/page/ -> NOT MATCHED
/doesnotexist.php -> NOT MATCHED
/doesnotexist.html -> NOT MATCHED
Hope this helps.
EDIT
I updated the rules above so that the actual files / directories are not redirected, and also make sure that any file .phpor .htmlnot is sent to profile.php.
source
share