.htaccess remove directory from url

For affiliate tracking purposes, my affiliates have to give out a url like this:
www.mydomain.com/affiliates/username

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?  
Large_FarvaAsked:
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
0
 
farzanjCommented:
Yes you can.
Use the following rule
RewriteRule "/affiliates/(.*)" $1
0
 
Large_FarvaAuthor Commented:
Excellent...thanks!
0
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.