1

We're trying to use redirect to allow our website editors to link to external pages, however when we use:

{exp:channel:entries}
  {redirect='{external_link}'}
{/exp:channel:entries}

It just takes them to http://example.com//http://www.myredirecturl.com

Is it possible to use redirect to link to external websites? Thanks!

2 Answers 2

7

Not with a tag, but with a PHP snippet you can, you have some options:

  1. Using EE's built on function

    <?php ee()->functions->redirect('{external_link}'); ?>
    

You'll need PHP parsing on, if you want to use the {external_link} tag you'll have to set it to run on Output

  1. Location Header redirect.

With the above you may get some screen artifacts as the template engine runs before the redirect. you can avoid this with a bog standard PHP redirect. Commonly known as a

<?php header('Location: {external_link}'); exit; ?>

This method you'll also need PHP on Output, so you can parse the {external_link} tag in the PHP snippet, but this should abort the template engine and redirect a bit cleaner. Make sure this statement is executed BEFORE you send anything to the browser.

  1. You could always set up a JS redirect and push the tag into some script, means loading the page before redirecting though, but no need for PHP parsing:

My personal favourite is option 2.

0
2

Why just using either snippet or direct put to template meta-part instead of using PHP in-template if editors put full URL?

Something like:

{exp:channel:entries}
  <meta http-equiv="refresh" content="0; url={external_link}">
{/exp:channel:entries}
1
  • Yep, this is also totally valid, option 3. Thanks Riverboy
    – Blatant
    Jun 22, 2015 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.