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?
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:
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 :)
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.
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:
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.
I think you can use the string property umbracoUrlAlias
http://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracourlalias
best regards
- Sune
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:
Is that any good to you?
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.'
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:
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
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.
With correct use of the canonical tag this shouldn't be an issue Thomas.
From my understanding he has some old functionality he is trying to pull over in which case its valid?
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.
is working on a reply...