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

a 夏天 提交于 2019-12-11 01:30:56

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/19236888/composite-c1-url-aliases-redirecting-urls-with-querystring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!