redirect 404's with .mt script/Location: Header
Sivakatirswami
katir at hindu.org
Mon Dec 31 23:42:01 EST 2001
on 12/29/01 8:21 AM, Chipp at metacard-request at lists.runrev.com wrote:
>
> You might try putting the following in a simple HTML response:
>
[snip]
>
> where location is the destination you wish to send the user.
>
> -Chipp
Well, putting an HTML page up to deal with single 404 redirects is exactly
what we want to get away from... already we have dozens and dozens of such
pages using old the "meta equiv" routine, and search engines and spiders no
longer follow those pages...(considered a kind of "web spam" where abusers
build 1000's of diversely named redirect pages to one or two pages of "real"
content) and so, even though people/spiders are hitting on them and being
redirected, they are not logged as valid hits by a search engine... But
thanks to a kind soul on the Apache list who ferreted out a bug in the
location directive (status directive is required) the following mc script is
close to functional.
.htaccess file at root (public_html/.htaccess) reads:
errorDocument 404 /cgi-bin/redirect.cgi
=====redirect.cgi in metaTalk:======
on startup
## first get Apaches special 404 environment variables that it passes
## with the 404 to the CGI. The important one being the requested page
## along with all kinds of other useful info...
put the globals into tGlobals
split tGlobals by cr & "="
## Load a small matrix file, line/"=" delimited with lines containing
## oldPath/file.html = newPath/correct.html
## You can also map location paths to absolute URLs like this:
## oldPath/file.html = http://www.newWebSite/newPath/correct.html
## you could keep this map right in the script if you preferred
## but will delegate the task of maintaining the map... so
## want it to be external to the script.
put url "file:404-new.txt" into urlMap
split urlMap by cr & "="
## Next we check to see if the requested page is in our matrix;
## if it is we poke the newUrl
if tGlobals["$REDIRECT_URL"] is among the keys of urlMap then
put urlMap[(tGlobals["$REDIRECT_URL"])] into newURL
## and now we do the redirect thing which is very simple
put "Status: 301 Moved Permanently" & cr
put "Location: " & newURL & cr & cr
else
## the requested URL is not in our map so we send a generic
## web page which is site map and a search engine interface
## prompting the user to see if he can locate what he wants
## somewhere within our seven domains/websites
## which file is in kept in the cgi-bin itself
put (url "file:custom404response.html") into buffer
put "Content-Type: text/plain" & cr
put "Content-Length:" && the length of buffer & cr & cr
put buffer
end if
end startup
Now, if you put your .htaccess file in a specific directory to handle a
specific missing page in that directory, then this is even simpler
on startup
put "someNewPath/foo.html" into newURL
## could also be absolute "http://www.URI.org/"
put "Status: 301 Moved Permanently" & cr
put "Location: " & newURL & cr & cr
end startup
Hinduism Today
Sivakatirswami
Editor's Assistant/Production Manager
katir at hindu.org
www.HinduismToday.com, www.HimalayanAcademy.com,
www.Gurudeva.org, www.hindu.org
Read The Master Course Lesson of the Day at
http://www.gurudeva.org/lesson.shtml
More information about the metacard
mailing list