|Last Word on 301s?|
301 redirects for part of website, SE friendly
| 3:45 am on Feb 22, 2006 (gmt 0)|
Okay, there is info about this everywhere, including here - some of it old, some of it new. But I want the most up-to-date, most correct, most SE friendly way of setting up 301 redirects for a few dozen pages of my website. Here's how it goes:
Old site: [oldsite.com...]
New site: [newsite.com...]
It's pretty straightforward as you can see, and it's only for a portion of the old website (the rest is staying at the old domain). I've seen 301s done a couple different ways - could someone tell me which is the real, right way? Thanks!
| 4:36 am on Feb 22, 2006 (gmt 0)|
There are many "real, right ways" to implement a 301 redirect. You can use mod_alias [httpd.apache.org], mod_rewrite [httpd.apache.org], or a script that outputs a 301-Moved Permanently status along with a new URL -- All will work, and the 'right way' would depend on your comfort level with the various approaches, and possibly on the privelege level granted to you by your hosting service.
It's not clear from your example which parts of the old and new URL-paths are fixed, and which parts (if any) are variable. If you just want to redirect a few URLs, then a simple list of case-by-case redirects would work.
If you want to redirect groups of URLs, say entire directories or URLs that all have "blue_widget" anywhere in them, then one approach might have an advantage over the other.
Taken literally, but assuming that all "pages.htm" in the /folder directory are to be redirected unconditionally, your example would be easiest to implement using the most-primitive redirect directive of Apache mod_alias:
Redirect 301 /folder/ http://www.newsite.com/folder/
The "Redirect" directive uses prefix-matching; Any part of the URL-path not specified in the source URL-path (which is "/folder/" in this example) is appended to the destination URL. So any value of "pages.htm" from the originally-requested URL would be appended to the new URL.
If you need to remove part of the original URL-path, or if you need to use regular-expressions to match certain 'kinds' of URLs, then the RedirectMatch directive would be a better choice. If you need to redirect depending on certain conditions of the request environment itself (say, redirect only for AOL users), then mod_rewrite would be better. And if the new URL cannot be directly-derived from simple substitution or rearrangement of the characters and fields of the old URL and request variables, then a scripted database lookup approach might be required.
Each of the above-listed methods brings increasing felxibility *and* complexity in turn.