Mango



Thread: Creating 301 redirects

Created on: 09/01/11 10:57 AM

New topic Reply    Page: 1  

Replies: 4
JackLeblond


JackLeblond's Gravatar
Joined: 11/05/10
Posts: 7

09/01/11 10:57 AM

Hello all -

I want to redirect a mango page to another URL.

ISAPI is not an option for me.

I've been trying to use tips picked up from related threads, but of yet I'm unsuccessful.

I've created a custom field named "RedirectPage" and have tried a couple variations on it's value - nothing seems to work.

I'm thinking code below should work if I enter the desired URL as the value of the custom field, but no luck

<mango:PageProperty ifHasCustomField='PageRedirect'>

<cfheader statuscode="301" statustext="Moved permanently">

<cfheader name="Location" value="<mango:PageProperty customField='PageRedirect' />">

</mango:PageProperty>


Any suggestions?
Link | Top | Bottom
visual28

Wizard
visual28's Gravatar
Joined: 05/18/08
Posts: 652

09/01/11 11:13 AM

on fist impressions, it looks like it should work. What is the value of PageRedirect? perhaps there is something in the value not working. Also can you post up a link to a page that has the code in place so we can see what is being output to the browser?

-
Mark - www.visual28.com | www.mangowear.com
Link | Top | Bottom
Laura

Wizard
Laura's Gravatar
Joined: 01/29/05
Posts: 1521

09/01/11 11:20 AM

No, that doesn't work. <mango> tags are custom tags, so when you say <cfheader .. value=<mango:>, the value for the page redirect is not evaluated, it is taken as a string. It is as if you would do something like:
<cfheader value="<cfset a = 1>"/> the cfset part wouldn't be evaluated, because it is simply a string.

You need to create your own custom tag, which will take the value of the current page like <mango> tags do. Check the PageProperty tag on how to do that.

However, the best way would be to use a plugin listening to the event that is triggered even before the page is rendered ("beforePageTemplate"), since you are going to redirect anyway.
Link | Top | Bottom
JackLeblond


JackLeblond's Gravatar
Joined: 11/05/10
Posts: 7

09/01/11 12:47 PM

Thanks Laura - appreciate the feedback. I've been trying to avoid creating plugins since my CF skills are not up to par, but it looks like I'll have to dust off the books.
Link | Top | Bottom
Laura

Wizard
Laura's Gravatar
Joined: 01/29/05
Posts: 1521

09/01/11 12:48 PM

Doing a custom tag might be easier to tackle.
Link | Top | Bottom

New Post

Please login to post a response.