Back, Next, and Previous links for the REFERRING term archive

HTTP and therefor web pages do not have any context, which is what you basically need, and only browsers can store context. You can add the context on the PHP side in a cookie, add to the page some JS code that inspects the cookie and based on it sets the actual url for the links you want to have.

for the benefit of people that do not have JS enabled, or google, set some “default” URL values there.