This may seem silly, but I can't figure out how to make a node redirect to a page that is on another website. Why do I have to pick a node locally? What am I missing here?
Thanks Doug, this works well-- problem is that it would seem I'd need another template for every node I want an external redirect for. Not very efficient. Can I feed in the URL from the page instance level rather than the template?? Could this be done?
Well that's what I'm Doing, but I can't put a Macro in a regular page on the Content tab. What I'm saying is in order to have a different instance of the Macro, I need a different Template, no?
I have a page on teh site called Client Login, which is an offsite link. I created a template called External Redirect, then specified that this Client Login page use this template. And as I said, it works. But what if I create another page that I want to redirect to somewhere else?? Then I would have to create another template, no? Are you saying I can have two different instances of the same Macro on the same template? If that's the case, then how will my new page know which instance to use?
I think what Casey is saying is that you need to add a property on the document type that the Client Login template uses, for instance you could add a property of TextString and call it "Redirect URL" with an alias "redirectURL".
Ok thanks now we're getting somewhere. Although if you enter the redirectURL into the page instance then I don't really see the point of the Macro, no? I'm sorry, but I don't understand how the Macro is going to know whether to get the URL from the Macro parameter or the Page property. Am I removing the Macro parameter?
When passing a macro parameter grabs the value from the page field of the current page. This allows it to do what you want, by passing the redirect url to the macro from a property no the current page, instead of setting up a new template each time.
Thank for your help. Listen, again, this is my first Umbraco implementation so I apologize for all the back and forth. Am I LITERALLY putting
[#propertyAlias]
into my code? Where? I am so confused. Now I have a Macro paramter called redirectURL AND a page property called redirectURL. Is this correct? Here is the code:
is the alias of the page property that contains the URL you wish to redirect to. Your code above looks correct, as long as redirectURL is also your page property.
Ok so my Macro paramater TYPE then should be propertyTypePicker, then, I'm assuming, and then when I insert the Macro in the ExternalRedirectPage template, I browse the list for the "redirectURL" property. The code then inserts like this:
No need to be sorry! It s not immediately obvious here.
The
[#propertyAlias]
Shouldnt be a macro parameter, its a field on the page. In this way it picks up your preferred url from the current page (node), and is not passed in when the macro is inserted.
So when setting up your page,
create a property/field called redirectURL of type textstring on the document type that you are redirecting from.
in the content tree, put the url you wish to redirect to in your new field on the page you are redirecting from
Make sure the page is using the the template with your redirect macro in it
On the template of the page to redirect from. This grabs the url that is stored in the content area for this page and passes it to the macro, so e.g. if you had hadded http://www.google.com into the redirectURL field of the current page, what the macro would really be getting would be
As it replaces the [#redirectURL] with the value stored on the current page using that alias.
it sounds like you have redirectURL as a node in the content tree? This shouldn't be the case. it should be a field added to the document type of a stanfard text page, allowing you to redirect as needed from any page. You don't need to use any macro parameters such as content pickers at all if you are getting the value from the current page.
Hope this makes sense - don't worry about posting back if you continue to have issues. Dan
I am getting the same result, having done exactly as described above. I have removed the Macro parameter, ensured that the content page is using the External Redirect template, and have inserted the Macro in that template exactly as above. The result is a blank page with <Macro: External Redirect (,)>. I don't have "redirectURL as a node in the content tree" as suspected. It's a page called Client Login, and I just need it to go offsite. The redirectURL field is populated on that page.
How does the Macro even KNOW that this is a redirect?? Where is THAT code?
The macro gets created when you install the redirect package from http://www.neehouse.com/. I don't know the exact params it requires, but to make sure it is installed and the syntax is correct be sure to use the "insert macro" button on the template editor from within umbraco, and not copy the code from the forum. Then there will be a popup asking you to enter the paramaters. For the URL simply enter [#redirectURL]and it should pick it up.
Anyhow - I've just adapted a bit of xslt from another post that does this with minimum fuss. Follow these instructions and you should be ok - I've just tested it as working and sending the following headers (for a redirect to google)
HTTP Status Code: HTTP/1.1 301 Moved Permanently Connection: close Date: Wed, 23 Sep 2009 17:46:56 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET Location: http://www.google.com Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 1723 Redirect Target: http://www.google.com
1. Copy and paste the code listed below into a new xslt file on your site (in developer section, right click>create from the xslt folder), making sure you keep "create macro" checked as you do it. You can call the xslt file whatever you want, the macro will have the same name.
<msxsl:script language="VB" implements-prefix="vb"> <msxsl:assembly name="System.Web"/> <![CDATA[ Public Function Redirect(url As String) System.Web.HttpContext.Current.Response.Status = "301 Moved Permanently" System.Web.HttpContext.Current.Response.AddHeader("Location", url.ToString) Return "" End Function ]]> </msxsl:script>
2. Insert the new macro into the template of your text page, and test by putting htttp://www.google.com into the redirectURL field for the page you are redirecting from, publish. Now visit the page and you should be redirected.
If this still doesn't work I'd check the following
Check that the field is on your document type and has an alias of redirectURL with the same casing
Check that the macro is inserted on your template
Check that the current page has the correct template applied.
HALLELUJAH!!!!!!!!!!!!!!!!!!!!!!!! How appropriate that "Dan" rhymes with "The Man" ;) I cannot thank you enough, my good sir-- works like a charm! And yeah, the XSLT approach is way simpler in my opinion. I see what you did there and learned from it.
Offsite Redirect
Hi,
This may seem silly, but I can't figure out how to make a node redirect to a page that is on another website. Why do I have to pick a node locally? What am I missing here?
//Garrett
The built-in umbracoRedirect property only sends you to another umbraco page. To get "outside" of your site, you'll need to use something else.
I've used Casey's redirect package and found it worked well. http://www.neehouse.com/umbraco_cms/packages/redirect.aspx. And there are surely others out there, or you could write your own pretty quickly.
cheers,
doug.
Thanks Doug, this works well-- problem is that it would seem I'd need another template for every node I want an external redirect for. Not very efficient. Can I feed in the URL from the page instance level rather than the template?? Could this be done?
//Garrett
Hi Garrett,
You can simply assign a property to the macro field and pass it from the node to the macro...
Of course, I am not referencing the exact macro, just giving an example.
Well that's what I'm Doing, but I can't put a Macro in a regular page on the Content tab. What I'm saying is in order to have a different instance of the Macro, I need a different Template, no?
I have a page on teh site called Client Login, which is an offsite link. I created a template called External Redirect, then specified that this Client Login page use this template. And as I said, it works. But what if I create another page that I want to redirect to somewhere else?? Then I would have to create another template, no? Are you saying I can have two different instances of the same Macro on the same template? If that's the case, then how will my new page know which instance to use?
Sorry and thanks!
//Garrett
I think what Casey is saying is that you need to add a property on the document type that the Client Login template uses, for instance you could add a property of TextString and call it "Redirect URL" with an alias "redirectURL".
Then the macro will know where to redirect.
Ok thanks now we're getting somewhere. Although if you enter the redirectURL into the page instance then I don't really see the point of the Macro, no? I'm sorry, but I don't understand how the Macro is going to know whether to get the URL from the Macro parameter or the Page property. Am I removing the Macro parameter?
Using the rather clever
[#propertyAlias]
When passing a macro parameter grabs the value from the page field of the current page. This allows it to do what you want, by passing the redirect url to the macro from a property no the current page, instead of setting up a new template each time.
Dan
Thank for your help. Listen, again, this is my first Umbraco implementation so I apologize for all the back and forth. Am I LITERALLY putting
[#propertyAlias]
into my code? Where? I am so confused. Now I have a Macro paramter called redirectURL AND a page property called redirectURL. Is this correct? Here is the code:
Sorry and thank you,
Garrett
[#propertyAlias]
is the alias of the page property that contains the URL you wish to redirect to. Your code above looks correct, as long as redirectURL is also your page property.
Hope this helps,
Dan
Ok so my Macro paramater TYPE then should be propertyTypePicker, then, I'm assuming, and then when I insert the Macro in the ExternalRedirectPage template, I browse the list for the "redirectURL" property. The code then inserts like this:
But on teh site when I click on the link for the page that uses this template, the redirect doesn't work; I simply get a blank page with this:
<Macro: External Redirect (,)>
I'm so sorry-- what I am I doing wrong here?
//Garrett
No need to be sorry! It s not immediately obvious here.
The
[#propertyAlias]
Shouldnt be a macro parameter, its a field on the page. In this way it picks up your preferred url from the current page (node), and is not passed in when the macro is inserted.
So when setting up your page,
Now use
On the template of the page to redirect from. This grabs the url that is stored in the content area for this page and passes it to the macro, so e.g. if you had hadded http://www.google.com into the redirectURL field of the current page, what the macro would really be getting would be
As it replaces the [#redirectURL] with the value stored on the current page using that alias.
it sounds like you have redirectURL as a node in the content tree? This shouldn't be the case. it should be a field added to the document type of a stanfard text page, allowing you to redirect as needed from any page. You don't need to use any macro parameters such as content pickers at all if you are getting the value from the current page.
Hope this makes sense - don't worry about posting back if you continue to have issues.
Dan
Hi. Thanks for being so patient.
I am getting the same result, having done exactly as described above. I have removed the Macro parameter, ensured that the content page is using the External Redirect template, and have inserted the Macro in that template exactly as above. The result is a blank page with <Macro: External Redirect (,)>. I don't have "redirectURL as a node in the content tree" as suspected. It's a page called Client Login, and I just need it to go offsite. The redirectURL field is populated on that page.
How does the Macro even KNOW that this is a redirect?? Where is THAT code?
The macro gets created when you install the redirect package from http://www.neehouse.com/. I don't know the exact params it requires, but to make sure it is installed and the syntax is correct be sure to use the "insert macro" button on the template editor from within umbraco, and not copy the code from the forum. Then there will be a popup asking you to enter the paramaters. For the URL simply enter [#redirectURL]and it should pick it up.
Anyhow - I've just adapted a bit of xslt from another post that does this with minimum fuss. Follow these instructions and you should be ok - I've just tested it as working and sending the following headers (for a redirect to google)
1. Copy and paste the code listed below into a new xslt file on your site (in developer section, right click>create from the xslt folder), making sure you keep "create macro" checked as you do it. You can call the xslt file whatever you want, the macro will have the same name.
2. Insert the new macro into the template of your text page, and test by putting htttp://www.google.com into the redirectURL field for the page you are redirecting from, publish. Now visit the page and you should be redirected.
If this still doesn't work I'd check the following
phew. Good luck!
Dan
HALLELUJAH!!!!!!!!!!!!!!!!!!!!!!!! How appropriate that "Dan" rhymes with "The Man" ;) I cannot thank you enough, my good sir-- works like a charm! And yeah, the XSLT approach is way simpler in my opinion. I see what you did there and learned from it.
Thanks again,
Garrett
How do we do this in C# and as a 302 redirect?
is working on a reply...