Installation and deployment
Version 3.x > Installation and deployment > 301 Redirects + ISAPI_Rewrite v3 View modes: 
User avatar
Member
Member
sc0ttkclark - 4/1/2009 9:48:03 AM
   
301 Redirects + ISAPI_Rewrite v3
We are running a server with Kentico 3.1a on it. We use ISAPI_Rewrite v3 to manage our redirects, but when it comes to redirecting pages that are in Kentico, the menu redirects built-in only do 302 Redirects.

Is it possible for me to change this somewhere in the Kentico core code?

Or is it possible to run the ISAPI_Rewrite engine before the Kentico Rewrite engine?

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 4/2/2009 5:21:34 AM
   
RE:301 Redirects + ISAPI_Rewrite v3
Hello,

rewriting is processed in this file:
~/App_Code/Global.asax.cs

The 301 redirection could be ensured inside the Application_BeginRequest method. You could check the current URL and add a code like this for example:

HttpContext.Current.Response.Status = "301 Moved Permanently";

I hope it could be helpful for you.

Best regards,
Helena Grulichova


User avatar
Member
Member
sc0ttkclark - 4/2/2009 7:16:25 AM
   
RE:301 Redirects + ISAPI_Rewrite v3
That's great to know, BUT where's the example code? Please provide the example code for making this happen and the installation instructions on how to add that code into the ~/App_Code/Global.asax.cs file.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 4/2/2009 7:55:53 AM
   
RE:301 Redirects + ISAPI_Rewrite v3
Hello,

you could place the code in the begging of Application_BeginRequest method in the Global.asax.cs file.

You could test the current URL or current alias path – some sample codes are here: http://devnet.kentico.com/docs/devguide/cmscontext_class.htm

If it is the one it should be redirected add this code:

HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", your_new_location);

I hope it could be helpful for you.

Best regards,
Helena Grulichova


User avatar
Member
Member
sc0ttkclark - 4/2/2009 9:13:37 AM
   
RE:301 Redirects + ISAPI_Rewrite v3
I'm very happy that you've replied with more information, however I really would like a clear-cut straight example on how to do this. Please provide the exact code to detect if you were on a page "http://www.mysite.com/Test.aspx" to redirect it to "http://www.mysite.com/NotTest.aspx"

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 4/14/2009 8:50:29 AM
   
RE:301 Redirects + ISAPI_Rewrite v3
Hello,

the example could be (line about 432 of Global.asax.cs file):

if (aliasPath == "/Test")
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", "http://www.mysite.com/NotTest.aspx");
}

but you would need to test it in your background.

Best regards,
Helena Grulichova

User avatar
Member
Member
lukejil_2004-hotmail - 7/13/2009 3:58:11 AM
   
RE:301 Redirects + ISAPI_Rewrite v3
Hello!

Can you also give me the exact code for let say for example, "http://www.mysite.com/products/?aid=CD363/" to be redirected to "http://www.mysite.com/products.aspx"


Thanks in advance.

Best regards,
Naning Purisima

User avatar
Member
Member
kentico_pavelk - 7/17/2009 4:09:41 PM
   
RE:301 Redirects + ISAPI_Rewrite v3
Hello,

Please find the code below.


if ((aliasPath == "/products") && (UrlHelper.CurrentURL.IndexOf("?") >= 0))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", "http://www.mysite.com/products.aspx");
}



Best Regards,
Pavel Knotek