Adding a conditional to redirect the 404 page to another 404 page?

Lambert Chan asked on July 5, 2019 19:20

I'm attempting to add a macro to the navigation of the current 404 page but if I understand correctly the url redirection under the navigations tab only redirects when that page link is requested and not when it's been redirected to.

How could I set up a check to re-redirect the 404 page to another page?
The macro that I've attempted with is:

{% Contains(CurrentBrowser.UrlReferrer, "site") ? "/site/404" : "/404" #%}

Correct Answer

Peter Mogilnitski answered on July 5, 2019 20:10

What you are looking for is random redirect web part. You can drop it on you 404 page and put there only one line with your macro. See example, but I would do it a bit differently I would put the URL with /site/404 inside the web part and enable/disable if based on your condition

0 votesVote for this answer Unmark Correct answer

Recent Answers


Lambert Chan answered on July 5, 2019 22:53 (last edited on July 5, 2019 23:21)

I wasn't aware of that webpart it works great now thanks!

0 votesVote for this answer Mark as a Correct answer

Lambert Chan answered on July 6, 2019 01:55

So it worked for some cases but not for all cases and I figured out that's because CurrentBrowser.URLReferrer only takes the previous link if it was a selection from the site. When an error in entering the url through the address bar occurs this isn't recorded by CurrentBrowser.URLReferrer and I can't seem to find another macro that checks instead through the currentbrowser's live url eg. www.mainsite/microsite/pagentofound showing pagentofound instead of the actual document's path or name of pagenotfound.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.