I need to change the url of a directory so that:
www.example.com/foo/
becomes
www.example.com
I can't move the files.
Putting a htaccess file using mod_rewrite to simply rewrite www.example.com to www.example.com/foo wasn't a problem
RewriteEngine On
RewriteRule !^foo/ foo%{REQUEST_URI} [L]
However I must ensure that if the user requests www.example.com/foo that the http status is 404 or the user is redirected to www.example.com. Unfortunately whatever I do, it seems to end up in an infinite loop. For example this results in an infinite redirection loop:
RewriteEngine On
RewriteRule !^foo/ foo%{REQUEST_URI} [L]
RewriteCond %{REQUEST_URI} ^/foo
RewriteRule ^foo(.*) http://www.example.com$1 [R=301,L]