>I have a custom 404 error page that uses that shows the URL of the page that
>couldn't be found using var="REDIRECT_URL". Is there a way to take this
>variable, such as "/folder/wrong.html", strip out everything except
>"folder", match "folder" and redirect (launch the web page) to
>"folder/index.html".

Depends. Three different ways to do it:

 * if you just want to redirect the user to the right place (without
   showing an interim page), then don't use Perl at all - look into
   your server (presumably Apache) capability. The following, in
   your httpd.conf or .htaccess file, will do the same thing, only
   without the additional Perl/CGI overhead:

Redirect /folder/wrong.html /folder/index.html

 * if you want to show an error page first, use a meta-refresh
   tag to automatically send the user to the right place. The
   following example would tell the user's browser to go the
   the rightplace.com after ten seconds. For accessibility,
   be sure to make this a clickable link somewhere on the page.

<META HTTP-EQUIV=Refresh CONTENT="10; URL=http://rightplace.com/";>

 * if you just want to redirect the user to the right page,
   only with your Perl/CGI script, do the following INSTEAD
   of a Content-type header:

     # instead of this:
     print "Content-type: text/html\n\n";
     print "Oopsies! Wrong page!";

     # do this. make sure that this line is the
     # ONLY thing you print out to the browser.
     print "Location: http://rightplace.com/\n\n";;

As for splitting up a URL into its
component parts, look into the URI
(pseudo code, not tested):

  my $url = "YOUR URL HERE";
  my $urih = URI->new;
  my $path = $urih->path($url);
  my @parts = $urih->path_segments($path);
  my $first_path = $parts[0];



--
Morbus Iff ( i put the demon back in codemonkey )
Culture: http://www.disobey.com/ and http://www.gamegrene.com/
Spidering Hacks: http://amazon.com/exec/obidos/ASIN/0596005776/disobeycom
icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to