Plugin

Developer
Supported

HS Redirect

ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Kevin Smith

1 of 2
1
   

You must be logged in to post.

Redirect Not Working

General

Brett DeWoody
Brett DeWoody

I’m trying to redirect a template based on a custom field. The custom field contains a full URL and my template looks like this:

{exp:channel:entries}
{exp
:hs_redirect location="{redirect-url}"}
{
/exp:channel:entries} 

Unfortunately it’s not redirecting to the URL. It’s just loading the template.

If I put anything else into the template (like {redirect-url}) it will spit that out on the page. Am I misunderstanding how this plugin works?

Kevin Smith
# 1
Developer
Kevin Smith

Hmm… I think the problem has to do with the parse order. Lowe created a great PDF for a talk at EECI2010 that I keep posted next to my computer that details the order in which EE parses variables, tags, etc. Check it out: http://loweblog.com/downloads/ee-parse-order.pdf

To get at your question specifically, I’m guessing {redirect-url} is a user-defined global variable? Or is it created using preload_replace?

Brett DeWoody
# 2
Brett DeWoody

{redirect_url} is a custom variable (defined on the publish entry page) that contains an absolute URL.

So if I do something like this:

{exp:channel:entries}
{redirect
-url}
{exp
:hs_redirect location="{redirect-url}"}
{
/exp:channel:entries} 

The URL will be displayed on the page, but the redirect doesn’t work.

Is there a way to use a custom variable in the location parameter?

Kevin Smith
# 3
Developer
Kevin Smith

For the sake of troubleshooting, if you replace the custom field tag {redirect-url} with a static url like http://google.com and leave everything else the same, does the template redirect properly?

Brett DeWoody
# 4
Brett DeWoody

Unfortunately not. My template contains just the {exp:channel:entries} loop with the {exp:hs_redirect location=“http://www.google.com”} in it.

Kevin Smith
# 5
Developer
Kevin Smith

Hmm… you’re using EE2, correct?

Would you mind creating a new test template with only the HS Redirect plugin’s tag in it. Something like this:

{exp:hs_redirect location="http://www.yahoo.com"

Let me know if that goes through.

Brett DeWoody
# 6
Brett DeWoody

EE2 - Version 2.1.3 Build 20101220

I removed the exp:channel loop so my template contains just the code you posted above. Still just goes to the template and doesn’t redirect.

Only other thing that I can think that might effect it is that I’m using Structure. So the pages where the hs_redirect is used is managed by Structure.  Could that be responsible?

Kevin Smith
# 7
Developer
Kevin Smith

Could be, but I don’t have a license for Structure, so I can’t test it out. I’m also not familiar with exactly how Structure modifies the core behavior of EE. Is there a way you could test it in an environment that isn’t managed by Structure. That would at least help us take a potential cause out of the equation.

Brett DeWoody
# 8
Brett DeWoody

I just created a new template (called ‘test’) and it contains:

{exp:hs_redirect location="http://www.yahoo.com"

But it still doesn’t process the redirect. If I put some filler text into the template that displays just fine, so I’m positive I’m hitting the correct template. When I remove the filler text a blank page appears and the redirect doesn’t happen.

Thanks for all the help!

Kevin Smith
# 9
Developer
Kevin Smith

No problem! This is so strange. What version PHP are you running under?

Just to try to circumvent a potential problem with PHP, try adding the script parameter to your test template.

{exp:hs_redirect method="script" location="http://www.yahoo.com"

That’ll use Javascript as the method for redirection instead. Might help us narrow down the problem.

Brett DeWoody
# 10
Brett DeWoody

Nope…. still just returns the template, with no redirect.

Sorry for all this trouble. If you don’t have time to support I can dive into the plugin and try to debug myself.

Kevin Smith
# 11
Developer
Kevin Smith

I’ve got a little free time today, no worries. What version PHP?

Kevin Smith
# 12
Developer
Kevin Smith

Btw, with the script method, it should actually be outputting javascript code to your HTML source, so you should be able to see it. Does it show up in the HTML page source?

Brett DeWoody
# 13
Brett DeWoody

The source is completely blank. Does it require that I have a <header> on the page? Cause right now the template is just the {exp:hs_redirect location=“http://www.yahoo.com”} tag and nothing else.

Kevin Smith
# 14
Developer
Kevin Smith

No, just the tag alone should do it. So that means the plugin isn’t outputting anything. Hmm… I wonder if something in the 2.1.3 update caused the plugin to break. Let me investigate a bit.

Brett DeWoody
# 15
Brett DeWoody

Sorry, PHP version is 5.2.14.

1 of 2
1