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);
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);
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
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 DominguezHi 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