.htaccess remove directory from url

For affiliate tracking purposes, my affiliates have to give out a url like this:

For me, there is no practical reason to send them to the affiliates directory but is required since the tracking application is in there.  The program actually redirects them to my homepage anyway so when they use the above link, they land on www.mydomain.com/

I would prefer to be able to use www.mydomain.com/username instead.   So essentially I just want to write out the "affliates" directory in the url so it appears in root.  

Can I do this with a rewrite in htaccess?  
Who is Participating?
lombardojaConnect With a Mentor Commented:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
RewriteRule ^$ affiliates [L]

This will redirect any requests that don't have a matching filename or directory on the server. This way, your site is still navigable but any requests to www.mydomain.com/username or mydomain.com/username will be rewritten to www.mydomain.com/affiliates/username
Yes you can.
Use the following rule
RewriteRule "/affiliates/(.*)" $1
Large_FarvaAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.