I am not an HTML designer... but thoe answers seem odd to me, since they are all exampels of things you would put on a PAGE... but a request for
www.foo.bar/ is a request for a DIRECTORY...
If you want a request for
www.foo.bar to redirect to
www.foo.bar/subdir, there's an immediate problem in that
www.foo.bar is a directory, not a page. If you "surf" to
www.foo.bar, you've got to hope they've set up some kind of automatic redirection already to take you to
www.foo.bar/index.html or whatnot instead. (Unless they allow browsing directories, which is generally not done)
I am assuming the code other people shared would go on that index.html or whatever the page is that you display when they request the directory.
In which case, why not just take that redirector and point it to the new resource?
Or perhaps you want to take a request for
www.foo.bar/index.html and a request for
www.foo.bar/mypage.html and have them BOTH translated to
www.foo.bar/subdir/index.html and
www.foo.bar/subdir/mypage.html? In that case, you'll want to set up an alias for the entire directory, or use mod_rewrite or something similar to rewrite the URLs "on the fly."
I don't know jack about IIS (except it sucks!) but here's how you'd accomplish each of the above on Apache:
1) Redirect requests for
www.foo.bar to a specific page:
AliasMatch ^/$ /var/www/subdir/index.html
2) Redirect all requests for /whatever.html to /subdir/whatever.html:
DocumentRoot /var/www
Change to:
DocumentRoot /var/www/subdir
*WARNING* The above will screw up any other subdirectories you've been using -- they'll all move out of scope. So you might want to do it another way:
You could rewrite it using something like the AliasMatch above -- but it would be a bit more complex, needing to preserve part of the initial request. I can't remember the apache syntax for that off the top of my head. Might be like a regular regexp:
AliasMatch ^/([^/]*)/+$ /var/www/subdir/$1
You'd have to check the docs to see if that's anything like right. Heh!
These sloutions are "better" because all the other proposed solutions require the user's browser to download two pages, increasing the amount of traffic to your site -- plus it's done in the HTML which just seems sloppy to me, I guess... HTML isn't there to control access to your webserver. Quite the opposite, in fact.
-Chris