Skip to content

Instantly share code, notes, and snippets.

@artlung
Last active March 19, 2026 15:40
Show Gist options
  • Select an option

  • Save artlung/bb8f1471292002071907557e9d038819 to your computer and use it in GitHub Desktop.

Select an option

Save artlung/bb8f1471292002071907557e9d038819 to your computer and use it in GitHub Desktop.
Redirects to a different search path, in Perl
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
my $query = $ENV{'QUERY_STRING'} || '';
my ($words) = $query =~ /words=([^&]+)/;
if (defined $words) {
$words =~ s/\+/ /g; # Replace + with space
$words =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; # Decode URL-encoded characters
print "Location: /search/?q=$words\n\n";
} else {
print "Location: /search/\n\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment