From bb223d27c2a4ba5348f6b858d7514e9e907f13cb Mon Sep 17 00:00:00 2001 From: Nathan Glasl Date: Tue, 13 Mar 2018 15:08:13 +1100 Subject: [PATCH] [FIX] Resolves an issue where setting an `alternate_base_url` caused infinite redirections (since the mapping ended up with an absolute link). --- README.md | 2 +- code/dataobjects/LinkMapping.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 618d36f..329ca71 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # [misdirection](https://packagist.org/packages/nglasl/silverstripe-misdirection) -_The current release is **2.2.24**_ +_The current release is **2.2.25**_ > A module for SilverStripe which will allow both simple and regular expression link redirections based on customisable mappings, either hooking into a page not found or replacing the default automated URL handling. diff --git a/code/dataobjects/LinkMapping.php b/code/dataobjects/LinkMapping.php index 4c9056a..ab7ca36 100644 --- a/code/dataobjects/LinkMapping.php +++ b/code/dataobjects/LinkMapping.php @@ -350,7 +350,19 @@ public function getLink() { // When appropriate, prepend the base URL to match a page redirection. - return MisdirectionService::is_external_URL($link) ? (ClassInfo::exists('Multisites') ? HTTP::setGetVar('misdirected', true, $link) : $link) : Controller::join_links(Director::baseURL(), $link); + $prepended = Controller::join_links(Director::baseURL(), $link); + if(MisdirectionService::is_external_URL($link)) { + return ClassInfo::exists('Multisites') ? HTTP::setGetVar('misdirected', true, $link) : $link; + } + + // This is needed, otherwise infinitely recursive mappings won't be detected in advance. + + else if(MisdirectionService::is_external_URL($prepended)) { + return $link; + } + else { + return $prepended; + } } }