I currently have an .htaccess file and what it does is, when someone types the url [noparse]http://example.com/username[/noparse], it calls the user_profile.php page in the backend and shows the user’s profile for the username supplied.
The contents of the ,htaccess file is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ user_profile.php?id=$1& [L,NC]
BTW. If you have a strict set of characters that usernames can consist of, like only letters, digits and dashes, change ^([^/]+)/?$ to the stricter version ( for my example that would be ^([a-zA-Z0-9-]+)/?$ )
Okay, than you can use the !-d option I showed you
Short answer: no
Longer answer: the .htaccess only affects Apache, so only calls to your website. All other protocols like mail (smtp, pop3, imap), ftp, ssh, etc. are not affected by the .htaccess.
That’s what RewriteCond %{REQUEST_FILENAME} !-f does
Let me comment the .htaccess for you
# Start the RewriteEngine, so we can use it
RewriteEngine On
# If the request is not (as per !) for an existing file (as per -f) ...
RewriteCond %{REQUEST_FILENAME} !-f
# ... and the request is not (as per !) for an existing directory (as per -d) ...
RewriteCond %{REQUEST_FILENAME} !-d
# ... redirect (request-uri) to user_profile.php?id=(request-uri)
RewriteRule ^([^/]+)/?$ user_profile.php?id=$1& [L,NC]
Does that make it clear?
PS. Just saw the [NC] on that RewriteRule. Since ^([^/]+)/?$ is case insensitive by default, you can drop that [NC].
[L] stands for Last, and basically says: stop processing the rules and go back to the start of the .htaccess. Normally Apache would process all rules in the .htaccess and then go back to the start, if the URL that came out of the .htaccess is different than the one that went in.
So you use [L] to make the .htaccess go faster, or take a shortcut - so to speak
[NC] stands for NoCase, which is to say “make this rule case insensitive”.
So if you have a rule for example like
RewriteRule ^test$ index.php [L]
that will match “test”, but it won’t match “Test”, “tEst”, “teSt”, “tesT”, “TEst”, etc
However
RewriteRule ^test$ index.php [L,[B]NC[/B]]
will match “Test”, “tEst”, “teSt”, “tesT”, “TEst”, etc
The thing is that you now have created an extra “directory”, so relative links don’t work anymore.
See section “Relative Links Are Missing!” on Apache’s mod_rewrite