Copied to clipboard

Flag this post as spam?

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


  • grazer 10 posts 31 karma points
    Jun 24, 2010 @ 07:01
    grazer
    0

    How can I assign multiple Urls to the one document?

    I'm converting an existing site to Umbraco and I have an existing url such as http://www.mysite.com/news/item/123456, where 123456 is the database Id of the news item.  I need to be able to maintain the url in Umbraco, but I'd like to not have to name each page "123456" etc.  Ideally I want the name of the page to be the name of the news article, so it's easier to find in the content tree.

    I know about UrlRewriting.config and originally figured on something like

    virutalUrl="~/news/item/([\d]*)" with destinationUrl="~/news.aspx?oldid=$1"

    In normal asp.net I would get the page to retrieve the entry with oldId = $1 and display it.  With templates, the page is already selected and I just insert the umbraco:Item for each property fo the Document Type.

    Perhaps I could write some xslt that takes the querystring and finds the appropriate node and creates the html to display.  then I could create a macro for it and use that macro on the page? 

    Another way I am thinking is add a Page.Load event to the template and use the Umbraco APi to find the correct node.

    The Document Type basically needs only the properties:

    • NewsArticle - The content imported from the old site
    • OldId - The database Id from the old site

    I was thinking I'd import the content using the API and opening a connection to the existing database.  Perhaps the above would be made easier if I set the umbracoNode.Id value to teh same value as the database?

     

    Any ideas on how to do this would be appreciated.

  • Fengelz 106 posts 221 karma points
    Jun 24, 2010 @ 13:11
    Fengelz
    1

    I think you can use the string property umbracoUrlAlias

    http://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracourlalias

    best regards 

    - Sune

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jun 24, 2010 @ 15:34
    Peter Duncanson
    0

    I'd go with your URL rewritting idea and have it direct off to a page which can then pull in the right Node using a XSLT macro and some XPath.

    Assuming you store the DB id in your nodes some how you can get the right node using umbraco's XSLT extension GetXmlNodeByXPath (see our.umbraco.org/wiki/reference/umbracolibrary/getxmlnodebyxpath), something like this:

    <xsl:variable name="oldDBId" select="umbraco.library:Request('id')" />
    <xsl:variable name="xpathQuery">
    <xsl:text>//node[string(data[@alias='umbracoNaviHide']) = $oldDBId]</xsl:text>
    </xsl:variable> <xsl:variable name="newsItem" select='umbraco.library:GetXmlNodeByXPath( $xpathQuery )" /> <xsl:value-of select="$newsItem/@data[@alias ='bodyText']" />

    Is that any good to you?

  • grazer 10 posts 31 karma points
    Jun 25, 2010 @ 00:33
    grazer
    0

    That's along the lines of what I was thinking Peter.  Thanks.

    I think I'm missing something because I can't get the above to work (once apostrophes are fixed up). I'm getting an error with:

    <xsl:variable name="newsItem" select="umbraco.library:GetXmlNodeByXPath($xpathQuery)" />

    I don't get an error if I replace $xpathQuery with a random string, '/node'. 

    Error is 'System.Xml.XPath.XPathException: Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.'

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jun 25, 2010 @ 12:29
    Peter Duncanson
    0

    Oops, yes. I've included a variable in the text for the xpath but that won't be expanded when we throw that into the function. Also we need to check the right field which I've called 'oldDBId' which will need to exist in your doc type. Try this instead:

    <xsl:variable name="xpathQuery">
        <xsl:text>//node[string(data[@alias='oldDBId']) = '<xsl:value-of select="$oldDBId" />']</xsl:text>
    </xsl:variable>

    Hopefully you can see why that way should work other the other. The function is just expecting a string for the xpath which I was giving as

    //node[string(data[@alias='oldDBId'])] = $oldDBId

    But the variable $oldDBId is useless here as the above is just a string! Where as the new version is still a string but I've injected the value of the variable rather than the variable name itself.

    //node[string(data[@alias='oldDBId'])] = '1234'

    Which is more like it! Give that a whirl (excusing up front any typos :)

    Pete

  • Thomas.R 39 posts 62 karma points
    Jun 25, 2010 @ 15:11
    Thomas.R
    0

    Hi,

    Maybe i've misunderstood something but having multiple URL's for the same document is not a good SEO practice, it is spamdexing.

    You should create 301 redirections, by using UrlRewritingNet or creating an HttpModule for example.

  • Dan 1288 posts 3921 karma points c-trib
    Jun 25, 2010 @ 15:15
    Dan
    0

    With correct use of the canonical tag this shouldn't be an issue Thomas.

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jun 25, 2010 @ 15:26
    Peter Duncanson
    0

    From my understanding he has some old functionality he is trying to pull over in which case its valid?

  • grazer 10 posts 31 karma points
    Jul 01, 2010 @ 07:39
    grazer
    0

    Thomas, I orginally went down the route of UrlRewriting to redirect but then, as Fengel said, umbracoUrlAlias worked and it's a easier than the UrlRewriting path I was going down (I may have been over-complicating it - as I started writting another Provider that would retrieve the oldId from the document using the API).

    I see from Dan's advice I should be includinge the umbraco.library.NiceUrl() result of the document id in <link rel="canonical" ... /> in my pages.

    The biggest issue with 301 Redirects (which semantically make a lot of sense) is adding all the direct rules when I've imported thousands of news pages into Umbraco, which was why I preferred to look up the correct page.  If there is a solution I'd be keen to hear it.  I could, I suppose, generate the entries to insert during the import process, then cut and paste into UrlRewritting.config.

    Not sure why Peter but I couldn't get your Xslt to work.  I kept getting errors about $xpathQuery not being a string. otherwise it all worked.  In the end I gave up and went with the simplest solution.  Especially given my inexperience with Umbraco & Web dev in general.

     

Please Sign in or register to post replies

Write your reply to:

Draft