Redirect to another page using Perl

Last updated on February 17th, 2022 at 06:59 pm

Click to rate this tutorial!
[Total: 0 Average: 0]

Sometimes there will be a requirement for websites to redirect users to different location. For example in case of a perl application, once authenticated if the user belongs to a specific group then that user can be redirected to concerned dashboard using this perl functionality.

Here is the code.

#!/usr/bin/perl
my $my_location = 'https://mistonline.in/wp/';
print "Location: $my_location\n\n";

Here all you need to modify is the PERL interpreter location (#!/usr/bin/perl) [According to Linux, UNIX, AIX or Windows Perl installed path] and also $my_location to your own webpage.

Sample Output

$ curl -IL http:///mywebsite/cgi-bin/redirect.pl
HTTP/1.1 302 Found
Date: Fri, 18 Feb 2022 02:51:31 GMT
Server: Apache/2.4.41 (Ubuntu)
Location: https://mistonline.in/wp/
Content-Type: text/html; charset=iso-8859-1

HTTP/2 200
date: Fri, 18 Feb 2022 02:51:31 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
wpo-cache-status: not cached
wpo-cache-message: The request method was not GET (HEAD)
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
server: cloudflare
cf-ray: 6df3f43fc9f98ce9-EWR
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
Click to rate this tutorial!
[Total: 0 Average: 0]

Leave a Reply

Your email address will not be published.