Search code examples
dotnetnukefriendly-urlvanity-url

How can I create a persistent vanity URL in DotNetNuke?


I'm not aware of a solution for implementing custom persistent vanity URLs (my term, not sure if thats what they're really called) in DotNetNuke. Does anyone know of a solution? It can be configuring the core, using a third party module, or a suggestion of how to write it from scratch.

Here is what I'm thinking:

  1. I want to point people to: http://mywebsite.com/awesome
  2. I want the underlying URL to be http://mywebsite.com/genericpage.aspx?key=awesome&etc=etc
  3. I don't want the URL to redirect. I want the user to see http://mywebsite.com/awesome only.

Essentially I'd envision an administrator being able to create these vanity URLs and specify what the vanity URL is and what the underlying URL is.


Solution

  • The closest thing, out of the box, is to define your friendly urls in SiteUrls.config found in the DotNetNuke root.

    This way:

    1. you point people to: http://mywebsite.com/awesome.aspx
    2. you have an underlying URL http://mywebsite.com/Default.aspx?tabid=ID&etc=etc
    3. users see: http://mywebsite.com/awesome.aspx

    Main restriction is that you will have an .aspx extension.

    SiteUrl.config rules look like this:

    <RewriterRule>
        <LookFor>.*/awesome.aspx</LookFor>
        <SendTo>~/default.aspx?tabid=ID&amp;etc=etc</SendTo>
    </RewriterRule>
    

    Rewriter rule matches incoming url to a regular expression in the LookFor section, and sends it to an underlying url in the SendTo section. You need to be careful with the XML escape character '&' in the querystring parameters.

    3rd party extensions like URL Master provide much more fine grained control, and you can have a global friendly url scheme based on page names, with or without .aspx extensions. Nevertheless, a simple "one url at a time" approach can be safer if you have custom modules with URL dependencies.