1 of 3
1
NEW - Redirect Plugin…
Posted: 09 February 2008 12:28 PM   [ Ignore ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4334
Joined  2006-04-15

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: 64)
pi.redirect_to_v1.2.zip  (File Size: 3KB - Downloads: 25)
 Signature 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

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

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 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4334
Joined  2006-04-15

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 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 15 February 2008 03:51 AM   [ Ignore ]   [ # 3 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4334
Joined  2006-04-15

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 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

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

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 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4334
Joined  2006-04-15

Hiya,

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

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

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

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 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4334
Joined  2006-04-15

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 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 21 February 2008 06:00 PM   [ Ignore ]   [ # 8 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  562
Joined  2007-07-02

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?

{if:else} is an advanced conditional. That means EE will parse everything inside of the {if} {/if} statement and just HIDE what doesn’t need to show up. So your plugin WILL parse (thus redirect) and EE will just hide the results. But since your plugin doesn’t give back results (it redirects) it will always redirect inside an advanced conditional smile

“(correct me if i am wrong here)”

 Signature 

Addons:
» EntryData Plugin (Get Custom_fields/etc without exp:weblog:entries)
» reCAPTCHA Extension (reCAPTCHA for comments)
» Paginatee Paginate text with page_titles
» Rewrite Redirect URL’s to new ones (301/302/etc)

Profile
 
 
Posted: 21 February 2008 06:04 PM   [ Ignore ]   [ # 9 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4334
Joined  2006-04-15

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

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

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

Thanks guys. I learn something new everyday.

 Signature 

T. Payton
OneCreative | Albuquerque, NM

Profile
 
 
Posted: 22 February 2008 04:13 AM   [ Ignore ]   [ # 11 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4334
Joined  2006-04-15

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 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 27 February 2008 10:52 AM   [ Ignore ]   [ # 12 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  613
Joined  2008-02-15

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!
Remember - If at first you don’t succeed, you’re not Chuck Norris

Profile
 
 
Posted: 27 February 2008 10:57 AM   [ Ignore ]   [ # 13 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4334
Joined  2006-04-15

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 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 27 February 2008 10:59 AM   [ Ignore ]   [ # 14 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  613
Joined  2008-02-15

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!
Remember - If at first you don’t succeed, you’re not Chuck Norris

Profile
 
 
Posted: 27 February 2008 11:10 AM   [ Ignore ]   [ # 15 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4334
Joined  2006-04-15

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 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 27 February 2008 11:14 AM   [ Ignore ]   [ # 16 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  613
Joined  2008-02-15

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!
Remember - If at first you don’t succeed, you’re not Chuck Norris

Profile
 
 
Posted: 27 February 2008 11:20 AM   [ Ignore ]   [ # 17 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4334
Joined  2006-04-15
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 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 15 March 2008 01:18 PM   [ Ignore ]   [ # 18 ]  
Grad Student
Rank
Total Posts:  87
Joined  2006-11-11

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
 
 
   
1 of 3
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 1149, on July 16, 2007 10:33 AM
Total Registered Members: 58259 Total Logged-in Users: 28
Total Topics: 68361 Total Anonymous Users: 17
Total Replies: 368153 Total Guests: 428
Total Posts: 436514    
Members ( View Memberlist )