Forum Moderators: phranque

Message Too Old, No Replies

cgi-bin .htaccess problem

I know why but how do I get around it

         

hannamyluv

10:26 pm on Dec 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



We are putting up a new site. The old links were:

www.site.com/cgi-bin/olddirectory/file.html

The new links are:

www.site.com/cgi-bin/newdirectory/file.html

The .htaccess isn't working on the cgi-bin (which I kind of understand why from reading other threads).

Is there a way around this though? What can I do so that all my old links are redirected correctly?

Chico_Loco

2:03 pm on Dec 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use a PERL script to catch 404's and redirect them with a 301.

1. Create a file in the OLD directory called 404.pl,

Here's the code for 404.pl

#!/usr/bin/perl

print "HTTP/1.0 301 Moved Permanently\n";
print "Location: /new-folder/$ENV{'SCRIPT_NAME'}\n";
print "Content-type: text/html\n";
print "\n";
print "<html>\n";
print "<head>\n";
print "<title>301 Permanently Moved</title>\n";
print "</head>\n";
print "<body>\n";
print "<h1>Permanently Moved</h1>\n";
print "The document has moved <a HREF=\"/new-folder/$ENV{'SCRIPT_NAME'}\">here</a>.<p>\n";
print "</body>\n";
print "</html>\n";

exit;
# End Code
----------------------------

2. CHMOD 404.pl to 755 (execution rights)
3. Create a .htaccess in the OLD directory and add this line:
ErrorDocument 404 404.pl

That should do it - let me know!