Search code examples
c1-cms

Composite C1 - 'URL Aliases', redirecting URL's with Querystring


I have a Composite C1 CMS site.

To maintain SEO juice, I need to redirect some old - mainly blog URLs - like this: http://www.mydomain.com/en/news/news.php?b=68 to http://mydomain.com/en/Blog/2013/04/30/Friendly-Article-Name

and

http://www.mydomain.com/en/news/news.php?b=69 to http://mydomain.com/en/Blog/2013/04/30/Another-Friendly-Article-Name

There are about 100 links to redirect.

The 'URL Aliases' module seems to work well, until you add a querystring (?b=68 above) - then it stops working.

How can I redirect several identical URL's, each with a different querystring?


Solution

  • That is definitely a bug in the Url Aliases package.

    The quickest way around this would likely be to roll your own http module, at least until a fix is published. You can snag the source from the package's repo on GitHub and tweak it to fix the issue, making sure that you unregister the bundled http module from web.config and register your own instead.

    The current http module source is here: https://github.com/CPHCloud/c1packages-urlaliases/blob/v1.0.2/CphCloud.Packages.UrlAlias/UrlAliasHttpModule.cs

    Change the value of incomingUrlPath to use PathAndQueryinstead of AbsolutePath, like this:

    ...
    static void httpApplication_BeginRequest(object sender, EventArgs e)
        {
            var httpApplication = (HttpApplication)sender;
            var incomingUrlPath = HttpUtility.UrlDecode(httpApplication
                .Context.Request.Url.PathAndQuery.TrimEnd(new[] { '/' }));
    ....
    

    In your web.config file you should unregister Url ALiases' handler

    <!--add name="UrlAlias" type="CphCloud.Packages.UrlAlias.UrlAliasHttpModule,
      CphCloud.Packages.UrlAlias, 
      Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /-->
    

    and register your own

    <add name="CustomUrlAlias" type="CphCloud.Packages.UrlAlias.UrlAliasHttpModule, 
      YourAssemblyName, 
      Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> 
    

    Full disclosure: I'm the author of the URL Aliases package.