Forum Moderators: open

Message Too Old, No Replies

Redirect users to correct language page

language asp forward

         

richiwatts

8:49 am on Sep 13, 2005 (gmt 0)

10+ Year Member



On my index.asp page I have added the code below which I hoped would check my visitors language settings and then redirect them to the local versions of our site. However, nothing happens. Is there anything wrong with the code or could I be doing anything else wrong? I have changed domain name according to site rules but you should get the idea:

<%
if (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "se") Then
Response.Redirect("http://www.domain.com/se/home.asp")
Elseif (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "de") Then
Response.Redirect("http://www.domain.com/de/home.asp")
Elseif (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "en-uk") Then
Response.Redirect("http://www.domain.com/uk/home.asp")
Elseif (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "en-us") Then
Response.Redirect("http://www.domain.com/us/home.asp")
End if
%>
<html>
<head>

mrMister

9:23 am on Sep 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My suspicion is that your own browser language is set to en-gb and therefore your script isn't matching it.

Your code is terribly inefficent by the way. You'd be better off with something like this...


<%
Dim strLanguage,strRedirect
strLanguage = lCase(Request.ServerVariables("HTTP_ACCEPT_LANGUAGE"))

Select Case strLanguage
Case "se"
strRedirect = "se"
Case "de"
strRedirect = "de"
Case "en-gb"
strRedirect = "uk"
Case "en-us"
strRedirect = "us"
Case "en"
strRedirect = "us"
Case Else
strRedirect = "uk"
End Select

Response.Redirect("http://www.domain.com/" & strRedirect & "/home.asp")
%>

richiwatts

11:34 am on Sep 13, 2005 (gmt 0)

10+ Year Member



Hi MrMister,

Thanks, that worked really well. Just one thing, how do I let all other countries/languages stay on the index.asp page so that they can choose their location from a drop down list?

Rich

mrMister

11:48 am on Sep 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remove the case else statement.

What I'd do is have a default language (probably English) and have links on each page to the various different language versions of your site.

Don't wary of dropdowns for navigation as search engines won't follow them. Also, take a look at the following usability guideline:

[useit.com...]

richiwatts

12:06 pm on Sep 13, 2005 (gmt 0)

10+ Year Member



Hi,

If I remove the else if statement it tries to go to:

www.domain.com//home.asp

Rich

mrMister

12:15 pm on Sep 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<%

 Dim strLanguage,strRedirect, booRedirect

 strLanguage = lCase(Request.ServerVariables("HTTP_ACCEPT_LANGUAGE"))

 booRedirect = True

 Select Case strLanguage

 Case "se"

 strRedirect = "se"

 Case "de"

 strRedirect = "de"

 Case "en-gb"

 strRedirect = "uk"

 Case "en-us"

 strRedirect = "us"

 Case "en"

 strRedirect = "us"

 Case Else

 booRedirect = False

 End Select

 If booRedirect Then Response.Redirect("http://www.example.com/" & strRedirect & "/home.asp")

%>

[edited by: Xoc at 12:17 am (utc) on Oct. 27, 2005]
[edit reason] changed to use example.com [/edit]