2

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?

niico
  • 11,206
  • 23
  • 78
  • 161

1 Answers1

2

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.

Magnus Kragelund
  • 370
  • 2
  • 10
  • Great thanks for that. Do you have any idea when *the developer* (wink) will get round to fixing it? – niico Oct 09 '13 at 11:26
  • Composite must review the package once it is submitted, so within a couple of days it should be up. I'll add it to the Github repo as a pre-release when i submit it, and post a link to the build. Then you can install it as a local package before Composite releases it to their Add-On Market. – Magnus Kragelund Oct 09 '13 at 13:23
  • Excellent - I can wait a couple of days. Thanks a lot. I've never 'updated' a package - do I uninstall then re-install? – niico Oct 10 '13 at 11:22
  • I've submitted the package now, i guess it will be up some time monday. Updating i not possible, so you have to uninstall and install again. Note that you will loose the aliases already created with version 1.0.2. – Magnus Kragelund Oct 13 '13 at 15:19
  • I've spotted a bug. If you try and set 301 redirect - save - it seems fine but when you edit the URL Alias again it says it's a 302. – niico Oct 16 '13 at 06:46