Site structure
Version 6.x > Site structure > 301 Redirect with query string View modes: 
User avatar
Member
Member
wynveen-dcim - 7/12/2013 9:49:04 AM
   
301 Redirect with query string
What is the best way to have Kentico 301 redirect a certain URL to one with a query string? The alias feature doesn't look like it has an easy way to do this.

Example:
User navigates to ~/product-accessories and is 301 redirected to ~/ProductSeries.aspx?productType=Accessories

I'm guessing I need to code these into the global.asax, but I'm not sure how to do it since I don't see a routes collection exposed in CMSHttpApplication.

User avatar
Kentico Support
Kentico Support
kentico_filipl - 7/12/2013 10:00:57 AM
   
RE:301 Redirect with query string
Hello,

You can achieve this goal by modifying ~\App_Code\Application\CMSAppBase.cs file - CMSBeginRequest() method, where you can check the current URL using CMS.GlobalHelper.UrlHelper.CurrentURL property, and according to it, you can redirect to a required URL with the following code:
CMS.GlobalHelper.UrlHelper.PermanentRedirect(String URLForRedirection);

which executes 301 redirect. This way you can set the redirection for all documents you need.

Best regards,
Filip Ligac

User avatar
Member
Member
wynveen-dcim - 9/24/2013 4:19:32 PM
   
RE:301 Redirect with query string
It turns out I had my requirements wrong on this. I don't need it to do a 301 redirect but just need it to be an alias for that page with the query string.

So, ~/product-accessories would show the same content as ~/ProductSeries.aspx?productType=Accessories, but the URL in the address bar would stay as ~/product-accessories

Is this possible? Looking at aliases, I don't see a way to add a query string on the end.

User avatar
Kentico Support
Kentico Support
kentico_filipl - 9/25/2013 9:26:29 AM
   
RE:301 Redirect with query string
Hello,

Well, document aliases can only be set for paths without query strings taken into account. So it can be achieved but it needs to be handled in code behind using the same principle as I suggested in my previous post. The only difference is that you will use Redirect(String URLForRedirection) method instead of PermanentRedirect().

Best regards,
Filip Ligac