Can missing language-specific pages fallback to default language? - General Discussions - General Discussions - Progress Community
 General Discussions

Can missing language-specific pages fallback to default language?

  • Can missing language-specific pages fallback to default language?
  • We've added a new language. We want missing pages to be redirected to the English equivalent. For example, if ~/zh/Services is missing, we want them redirected to ~/en/Services. Right now the user gets a 404 error.

    We don't want to have to do this manually for every page. Is there some global setting we can use, or some code we can add?

     

    Hm, no replies? So...is our only choice to manually instantiate zh versions of every page, and have each redirect to the existing en version?

  • Hi Chris,

    You can try redirecting to the desired page in the Application_Error event in global.asax. E.g:

    protected void Application_Error(object sender, EventArgs e)
           
               var ex = Server.GetLastError() as HttpException;
               if (ex != null)
               
                   int httpCode = ex.GetHttpCode();
                   if (httpCode == 404)
                   
                        
                       string urlSegment = this.Context.Request.Url.Segments[this.Context.Request.Url.Segments.Length-1];
     
                       this.Context.Response.Redirect("/en/" + urlSegment);
                   
               
     
           


    Regards,
    Junior Dominguez
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • Thanks, I'll try that!

    EDIT: Not working yet.

    I added the global.asax,  added your code to the Application_Error handler, and rebuilt. I made one change, because I think a true 404 would otherwise cause an infinite loop:

    if (httpCode == 404)
        if (this.Context.Request.Url.Segments[1] == "zh/")
        
            string urlSegment = this.Context.Request.Url.Segments[this.Context.Request.Url.Segments.Length - 1];
            this.Context.Response.Redirect("/en/" + urlSegment);
        

    But this hasn't made a difference, I still see the 404 page with the same missing URL. (I also restarted IIS, just to be sure.)

  • Hi Chris,

    Can you please provide some feedback about your results ? What happen when you debug it ? Is it redirecting to another location? 

    Best Regards,
    Junior Dominguez
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • Is there another solution to this problem?

    I do not like the "Application_Error" solution - I should not have to manually redirect to the English version of the page.

     

    Furthermore, redirecting to the "en" version, will put Sitefinity in English mode.  This causes problems if you are using a language-specific .resx file.  For example, if a user requests "/fr/home" and I redirect them to "/en/home" it means that the English version of my .resx files will be chosen, which is not the desired result.

  • Hi Patrick,

    You may consider the alternatives described in the following link of our documentation and customize the error message depending on the culture in the widget:

    http://docs.sitefinity.com/administration-custom-error-pages

    Best Regards,

    Junior Dominguez
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • Hi Guys,

    What i did was I created a Redirect Widget and put it inside the page. So this translated page will redirect to wherever i like.

    Just a quick fix i can't find a solution to this right now. Any suggestion?

    Thanks