This is one of those entries I make after finally learning how to do something I've wanted to know how to do for awhile. I make these entries for two reasons: 1) it's theoretically possible I might forget what I learned, and 2) someone else might have been wondering the exact same thing, and if I had difficulty finding a place where the information was spelled out (no matter how available and easy to find the information might actually be), I think it's possible someone else might have had the same difficulty.
If you go to http://en.wikipedia.org (for example), you'll be redirected to
So here's how to do exactly what Wikipedia (and probably trillions of other sites) does: create (if it doesn't exist) the .htaccess file in the directory you want to redirect. Then add this line:
Redirect 301 /index.html http://destination.site.example.com/path/to/page/
If you leave out the 301, the browser will be told the page has moved temporarily. If you include the 301, the browser will be told the page has moved permanently.
because otherwise, it'd be an infinite loop (Redirect matches a prefix).RedirectMatch ^/(index.html)?$ http://en.wikipedia.org/wiki/Main_Page
Re:Not quite
jdavidb on 2005-03-22T03:59:49
Ah, I see. The trailing slash in my example does indeed cause that problem (which I also discovered when I was trying to get this to work, and I simply redirected / to
/dir/). In the real-life versions I set up tonight, this wasn't an issue.
Re:Pointless redirects
jdavidb on 2005-03-23T14:54:09
Wikipedia may have its reasons, but there are far too many sites that redirect their front pages to some other URL. Why can't these people just set up their servers to give me the right content when I ask for "/" in the first place?
In my case it's because I'm using a cheapo hosting service and don't have that kind of access to the server.
Re:Pointless redirects
vsergu on 2005-03-23T15:07:22
I don't know the details of what you're doing, but if you have access to useRedirect
in an.htaccess file there may be ways to get what you want without a redirect. For example, you can use DirectoryIndex
inside.htaccess. You may even have mod_rewrite available. Re:Pointless redirects
jdavidb on 2005-03-23T17:41:23
Thank you. I will look into those to see if they better provide what I want.