I recently had a problem where I was doing some work on a project and was working on my local machine from the directory http://localhost/mysitename/site/. The problem I was having is that all of my URL's were pointing towards the root of http://localhost/, for example the login link was http://localhost/user when it should have been http://localhost/mysitename/site/user.
Naturally I checked my .htaccess file and everything seemed to be in order; 'RewriteBase /' was commented out. I tried flushing the cache, disabling modules I'd installed - anything I could think of. Nothing.
As with all these things the problem turned out to be incredibly basic. When I'd begun working on the site I copied the settings.php file from the 'stage' site folder, and altered the database settings to direct towards my localhost.
What I'd forgotten to do was comment out a line in my settings file around line 242;
$base_url = 'http://mysitename.stage.davidsonj.com'
Why this directed all my links to localhost instead of that domain - I can't be sure of. But once I'd commented that line back out, everything seemed to work fine again.
A very basic mistake, but one that I didn't find anywhere when trying to find a solution to this problem.