Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Garrett Fisher 341 posts 496 karma points
    Sep 22, 2009 @ 17:16
    Garrett Fisher
    0

    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

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Sep 22, 2009 @ 17:28
    Douglas Robar
    1

    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.

  • Garrett Fisher 341 posts 496 karma points
    Sep 22, 2009 @ 17:47
    Garrett Fisher
    0

    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

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Sep 22, 2009 @ 19:50
    Casey Neehouse
    2

    Hi Garrett,

    You can simply assign a property to the macro field and pass it from the node to the macro...

    <umbraco:Macro alias="ExternalRedirect"  Redirect="[#propertyAlias]"/>

    Of course, I am not referencing the exact macro, just giving an example.

  • Garrett Fisher 341 posts 496 karma points
    Sep 22, 2009 @ 20:21
    Garrett Fisher
    0

    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

  • Rich Green 2246 posts 4008 karma points
    Sep 22, 2009 @ 20:47
    Rich Green
    0

    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. 

    <umbraco:Macro alias="ExternalRedirect"  Redirect="[#redirectURL]"/>

     

  • Garrett Fisher 341 posts 496 karma points
    Sep 23, 2009 @ 15:33
    Garrett Fisher
    0

    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?

  • dandrayne 1138 posts 2262 karma points
    Sep 23, 2009 @ 16:03
    dandrayne
    0

    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

     

  • Garrett Fisher 341 posts 496 karma points
    Sep 23, 2009 @ 17:03
    Garrett Fisher
    0

    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:

    <umbraco:Macro redirectURL="[#redirectURL]" Alias="ExternalRedirect" runat="server"></umbraco:Macro>

    Sorry and thank you,

    Garrett

     

     

  • dandrayne 1138 posts 2262 karma points
    Sep 23, 2009 @ 17:17
    dandrayne
    0
    [#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

     

  • Garrett Fisher 341 posts 496 karma points
    Sep 23, 2009 @ 17:39
    Garrett Fisher
    0

    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:

    <umbraco:Macro redirectURL="redirectURL" Alias="ExternalRedirect" runat="server"></umbraco:Macro>

     

    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

  • dandrayne 1138 posts 2262 karma points
    Sep 23, 2009 @ 18:47
    dandrayne
    0

    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

    Now use

    <umbraco:Macro redirectURL="[#redirectURL]" Alias="ExternalRedirect" runat="server"></umbraco:Macro>

    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

    <umbraco:Macro redirectURL="http://www.google.com" Alias="ExternalRedirect" runat="server"></umbraco:Macro>

    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

  • Garrett Fisher 341 posts 496 karma points
    Sep 23, 2009 @ 19:07
    Garrett Fisher
    0

    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?

  • dandrayne 1138 posts 2262 karma points
    Sep 23, 2009 @ 19:51
    dandrayne
    0

    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.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:vb="urn:the-xml-files:xslt-vb"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="umbraco.library">
    <xsl:output method="html"/>

    <xsl:param name="currentPage"/>


    <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>

    <xsl:variable name="redirectUrl" select="$currentPage/data [@alias='redirectURL']" />

    <xsl:template match="/">
    <xsl:if test="string($redirectUrl) != ''">
    <xsl:value-of select="vb:Redirect($redirectUrl)"/>
    </xsl:if>
    </xsl:template>


    </xsl:stylesheet>

    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.

    phew.  Good luck!
    Dan

  • Garrett Fisher 341 posts 496 karma points
    Sep 23, 2009 @ 20:11
    Garrett Fisher
    0

    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

  • Connie DeCinko 931 posts 1160 karma points
    Aug 03, 2010 @ 18:23
    Connie DeCinko
    0

    How do we do this in C# and as a 302 redirect?

     

Please Sign in or register to post replies

Write your reply to:

Draft