Alias in Tridion

By | October 21, 2008

The goal of an alias is to create a link to some article on your web page that is short and descriptive enough for your audience to remember. Application could be for a TV commercial or printed media. In these cases you want to keep the URL short and simple.

For example the url http://website.domain.com/products/2008/1235469/default.aspx is impossible to remember. Therefore you want to be able to create a link like www.domain.com/alias. I have seen a number of interesting and very complicated solutions to this problem. However the easiest way to implement it is the following:

  1. Add the meta data field “alias” to all content schema’s for which content you want to be able to create aliases.
  2. Add aliases to your content and republish the content you changed.
  3. Add the code below to your 404.asp (or translate it into the language of your choice)
    Function ReturnUrl(alias)
    ReturnUrl = “”
    Dim objConnAlias, objRsAlias, SQL

    Set objConnAlias = server.createobject(“ADODB.Connection”)
    objConnAlias.ConnectionTimeout = 30
    objConnAlias.CommandTimeout = 30
    objConnAlias.Open Session(“ConnectionString”) ‘put your connection string here
    SQL = “SELECT PUBLICATION_ID, ITEM_ID FROM CUSTOM_META WHERE (KEY_NAME = ‘alias’) AND (KEY_STRING_VALUE = ‘” & Escape(alias) & “‘)”
    Set objRsAlias = objConnAlias.Execute(SQL)

    If Not objRsAlias.eof Then
    Dim publicationID
    publicationID = objRsAlias(“PUBLICATION_ID”)
    Set link = objCompLink.GetLink(“tcm:0-” & publicationID & “-1”, “tcm:” & publicationID & “-42334-64”, “tcm:” & publicationID &”-” & objRsAlias(“ITEM_ID”), “tcm:0-0-0”, “”, ” Read More “, true, false)
    ReturnUrl = link.url
    end if

    Set objRsAlias = Nothing
    Set objConnAlias = Nothing
    End Function

  4. Response.Clear
    Response.Status = 301
    Response.AddHeader “Location”, ReturnUrl(alias)
    Response.Flush
    Response.End