1 of 4
1
NEW - Redirect Plugin…
Posted: 09 February 2008 12:28 PM   [ Ignore ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10830
Joined  04-15-2006

Hiya,

A really quick post this one and a really simple plugin but it may come in handy for someone somewhere.

Plugin Usage :

This plugin is exceptionally simple to use. Place the following tag on any template as shown below :

Using full URL - useful for external sites.

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

or using paths instead - useful for internal links.

{exp:redirect_to location="news/detail/news_story"}

By default PHP redirection will be performed. If PHP redirection does not work,
use javascript redirection by adding method=“script” parameter.

{exp:redirect_to location="news/detail/news_story" method="script"}

If it is impossible by usual means to check if condition for redirection was met or not you can
check it by wrapping the code expressing condition by {exp:redirect_to}{/exp:redirect_to} tags.
Redirection will be performed if the code wrapped by {exp:redirect_to}{/exp:redirect_to} tags will produce
no output.

{exp:redirect_to location="my_template_group/my_template" method="script"}
{exp
:query sql="SELECT title FROM exp_weblog_titles WHERE weblog_id = '5' AND url_title ='My title'"}
{title}
{
/exp:query}
{
/exp:redirect_to}


If you want that redirection would be performed on condition that certain output were produced, you should
enter expected string as a value of “tagdata”  parameter. Then the redirection will be performed if
the string entered as “tagdata” parameter value and output of the code
wrapped by {exp:redirect_to}{/exp:redirect_to} tags are identical. (Tabs, spaces and new line characters
will be stripped.) In example below redirect will occur if {exp:query tag} will produce string “1”.

{exp:redirect_to location="my_template_group/my_template" tagdata="1" method="script"}
{exp
:query sql="SELECT title FROM exp_weblog_titles WHERE weblog_id = '5' AND url_title ='My title'"}
{total_results}
{
/exp:query}
{
/exp:redirect_to}

Basically if you place this into a template then you will be re-directed to the URL specified in the location parameter.


Hope it helps.

Best wishes,

Mark

File Attachments
pi.redirect_to.php_V1.1.zip  (File Size: 2KB - Downloads: 393)
pi.redirect_to_v1.2.zip  (File Size: 3KB - Downloads: 634)
 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 14 February 2008 12:10 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  161
Joined  03-19-2007

Hey Mark, interesting little nugget. I assume EE variables can be used within this parameter? Such as:

{exp:redirect_to location="http://www.mysite.com/new_directory/{weblog}/{url_title}/"}

Or perhaps:

{exp:redirect_to location="http://www.mysite.com/new_directory/{segment_3}/"}

Also, is there a delay on this rederict? And forgive a novice’s question - how does this compare with a meta-equiv?

Thanks!

 Signature 

—Kevin

Profile
 
 
Posted: 15 February 2008 03:44 AM   [ Ignore ]   [ # 2 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10830
Joined  04-15-2006

Hi Kevin,

I must admit I hadn’t even checked to see if those would work or not but I just tried with your second example with the {segment_3} option and that seems to work fine. The top one I haven’t tried yet but not too sure where you are getting those variables from? For instance the {weblog} variable. Is that a Global variable that you have created?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 15 February 2008 03:51 AM   [ Ignore ]   [ # 3 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10830
Joined  04-15-2006

Oops sorry meant to answer the second bit too!!

The documentation for that function in ExpressionEngine says the following :

redirect(location [string])

Redirect to location.
Class: Functions (FNS)
Description: Redirects current browser page to location. Does redirect either by location or meta refresh, depending on the redirect method preference.

Hope that answers the second question as to tell the truth I wasn’t too sure myself wink

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 21 February 2008 04:52 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  251
Joined  11-16-2004

Mark,

Sweet plugin. However I was trying to us it within an if statement and can’t get it to work properly (it seems to redirect regardless).

Have you had a chance to use it in an if statement?

- T.

 Signature 

T. Payton
OneCreative | Albuquerque, NM

Profile
 
 
Posted: 21 February 2008 04:56 PM   [ Ignore ]   [ # 5 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10830
Joined  04-15-2006

Hiya,

In what way are you using it in an IF statement? Can you show some code?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 21 February 2008 05:43 PM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  251
Joined  11-16-2004

Mark here is what I got:

{if segment_3 == "{exp:member:custom_profile_data}{pebble_group}{/exp:member:custom_profile_data}" }
You are on the right page
.
{if:else}
You are on the wrong page my friend
. Let me redirect you.
{exp:redirect_to location="http://www.mysite.com/group/"}
{
/if}

If I leave out your redirect code the text outputs properly. With your code, it redirects regardless of weather the conditional is true or not.

 Signature 

T. Payton
OneCreative | Albuquerque, NM

Profile
 
 
Posted: 21 February 2008 05:47 PM   [ Ignore ]   [ # 7 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10830
Joined  04-15-2006

Hmm,

I just tried it out and as you are seeing it doesn’t work but I did try a simple :

{if segment_3 == "test"}
Spit out this text
{
/if}

{if segment_3
== "none"}
{exp
:redirect_to location="http://www.mysite.com/group/"}}
{
/if}

That seems to work fine. Not too sure what is up with the ifelse structure though. Perhaps one of the admins could pop in here and let us know?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 21 February 2008 06:04 PM   [ Ignore ]   [ # 8 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10830
Joined  04-15-2006

Sounds good to me but then I’m not really sure either!! wink

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 21 February 2008 06:52 PM   [ Ignore ]   [ # 9 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  251
Joined  11-16-2004

Thanks guys. I learn something new everyday.

 Signature 

T. Payton
OneCreative | Albuquerque, NM

Profile
 
 
Posted: 22 February 2008 04:13 AM   [ Ignore ]   [ # 10 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10830
Joined  04-15-2006

Thanks for the thanks but they really should go to Victor grin

Hope the extra if statements work for you though and thanks for the comment on the plugin!! grin

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 27 February 2008 10:52 AM   [ Ignore ]   [ # 11 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1130
Joined  02-15-2008

Hey Mark,

This is perfect for my current need. However I think I’ve run up against the advanced conditional problem too:

{if logged in}
    
Do this
{
/if}

{if logged_out}
   {exp
:redirect_to location="/members"}
{
/if}

Is there an easy way I can get around this issue?

Hope someone can help,
Andy.

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter | New to ExpressionEngine? Start here!

Profile
 
 
Posted: 27 February 2008 10:57 AM   [ Ignore ]   [ # 12 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10830
Joined  04-15-2006

Hi Andy,

Hmm yes it does seem to be a problem with these conditionals. I will have to look into that when I get the chance. For now though could you possibly embed a template that does what you need?

Something like :

{if logged_in}
{embed
="do_this_template"}
{
/if}

{if logged_out}
{embed
="redirect-to-template"}
{
/if}

Not sure if that would work but hopefully it will?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 27 February 2008 10:59 AM   [ Ignore ]   [ # 13 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1130
Joined  02-15-2008

It’s certainly worth a try, I’ll give it a bash (so to speak) and let you know how it goes.

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter | New to ExpressionEngine? Start here!

Profile
 
 
Posted: 27 February 2008 11:10 AM   [ Ignore ]   [ # 14 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10830
Joined  04-15-2006

Hi Andy,

I just gave this a try and it will definitely do what you need. Also just noticed that in your code you had logged in instead of logged_in. Not sure if that will help with this though although that code is incorrect.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 27 February 2008 11:14 AM   [ Ignore ]   [ # 15 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1130
Joined  02-15-2008

I’m delighted to say that it wasn’t because I’d missed that underscore because right now I would be feeling unbelievably foolish.

And I’m equally delighted to confirm that the include method works fine too so that’s perfect for this particular need. Thanks lots and indeed ‘doozazzle’.

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter | New to ExpressionEngine? Start here!

Profile
 
 
Posted: 27 February 2008 11:20 AM   [ Ignore ]   [ # 16 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10830
Joined  04-15-2006
Andy Harris - 27 February 2008 11:14 AM

I’m delighted to say that it wasn’t because I’d missed that underscore because right now I would be feeling unbelievably foolish.

wink

Andy Harris - 27 February 2008 11:14 AM

And I’m equally delighted to confirm that the include method works fine too so that’s perfect for this particular need. Thanks lots and indeed ‘doozazzle’.

No problem at all. Well done on the doozazzle. Sorry if I bored you with what was above it? Let’s not give the game away to everyone in the forums though!! wink

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 15 March 2008 01:18 PM   [ Ignore ]   [ # 17 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  292
Joined  11-11-2006

Hi Mark, didn’t know where to post my question about you wiki article (Redirect User Upon Logging In) as I wasn’t able to post a question on the wiki. I’m having a problem where FireFox isn’t redirecting to the url specified in the cookie. Was wondering if this is a know problem?

Wiki article: http://expressionengine.com/wiki/Redirect_User_Upon_Logging_In/

Best wishes
Lee

Profile
 
 
Posted: 28 March 2008 04:26 PM   [ Ignore ]   [ # 18 ]  
Summer Student
Total Posts:  22
Joined  04-15-2006

Mark:

I’m attempting to build a simple search that would accomplish the following:

Keyword is not found - send to “keyword not found” page.

Keyword is found - redirect browser to the value stored in the “keyword_url” field.

I can get the search to return the “keyword_url” value with no problems… all by itself by using this code:

{exp:search:search_results}{keyword_url}{/exp:search:search_results}

And, I can get your plugin to work just fine placing a simple URL into it -

{exp:redirect_to location="www.yahoo.com"}

However, if I attempt to combine the two by placing the keyword_url inside the plugin I get an invalid URL:

{exp:redirect_to location="{exp:search:search_results}{keyword_url}{/exp:search:search_results}"}

The Invalid URL is:

http://www.panhandleparade.com/index.php/keywords/results/f4c187fcd506cbc4692df65e5bbe434a/{exp:search:search_results}{keyword_url}{/exp:search:search_results}

I’m guessing the EE code to extract the “keyword_url” value is not working inside the plugin code…

The simple search page is here:  http://www.panhandleparade.com/index.php/keywords/simple_search/

The single good keyword in the system at this time is “bagpipes” and the keyword_url is http://www.bagpipes.com

(I’m not into bagpipes, it’s just what I chose to test with)

Any thoughts?

 Signature 

Gene Hilsheimer
wmbb.com
Panama City, FL

Profile
 
 
   
1 of 4
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120453 Total Logged-in Users: 60
Total Topics: 126533 Total Anonymous Users: 38
Total Replies: 665353 Total Guests: 347
Total Posts: 791886    
Members ( View Memberlist )