Last active
March 14, 2022 15:33
-
-
Save jesusbagpuss/a5c574e1839612ef7e332d1d25edac42 to your computer and use it in GitHub Desktop.
EPrints redirect specific URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use EPrints::Const; | |
my %rewrite_map = ( | |
123 => 'https://other.site/321', | |
456 => 'https://else.where/stuff-999', | |
); | |
$c->add_trigger( EP_TRIGGER_URL_REWRITE, sub { | |
my( %o ) = @_; | |
# Might need to consider $o{urlpath} here e.g. | |
# if( $o{uri} =~ m!^/$o{urlpath}/(\d+)/! ) | |
if( $o{uri} =~ m!^/(\d+)/! ) | |
{ | |
my $eprintid = $1; #captured above | |
if( defined $rewrite_map{$eprintid} ) | |
{ | |
EPrints::Apache::AnApache::send_status_line( $o{request}, 301, "Moved Permanently" ); | |
EPrints::Apache::AnApache::header_out( $o{request}, "Location", $rewrite_map{$eprintid} ); | |
EPrints::Apache::AnApache::send_http_header( $o{request} ); | |
${$o{return_code}} = EPrints::Const::DONE; | |
return EP_TRIGGER_DONE; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment