Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Claushingebjerg 936 posts 2571 karma points
    Oct 22, 2010 @ 13:07
    Claushingebjerg
    0

    language version as subdirectory

    im sure this is really simple, but i cant get it to work...

    i have two language versions of my site.

    Each version resides as a root node.

    I want the main site to have the base url www.mysite.com

    i want the alternative language version to have the base url www.mysite.dk/dk

    I have added www.mysite.com and www.mysite.com/dk as hostnames to the two sites.

    When looking at the urls listed on a random page's properties pane, the url looks right, but the page doesnt display on the url... i simply get an error

    Am i missing a setting somewhere?

  • Eduardo 106 posts 130 karma points
    Oct 26, 2010 @ 09:13
    Eduardo
    0

    Hi Claushing,

    Have you tryed republishing the nodes?

    Regards,
    Eduardo

  • Rik Helsen 670 posts 873 karma points
    Oct 26, 2010 @ 10:45
    Rik Helsen
    0

    What we normally do is create a parent node called "languageswitch", where we have an ascx macro that checks the visitors browser language and then redirects to site.com/en or site.com/dk depening on their browser locale.

    The language specific nodes are below a "languageswitch page" in my case, and it works like a charm.

    An old formpost about this:

    What we do is create a "variationroot" documenttype/masterpage, that contains only a macro that holds a usercontrol that checks the language of the visitors browser settings and redirects the user to the subsite of his preferred language

    Variationroot.master:

    <%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>

    <asp:Content
     
    ContentPlaceHolderID="ContentPlaceHolderDefault"
     
    runat="server">
      <umbraco:Macro
     
    Alias="LanguageRedirectControl"
     
    runat="server"></umbraco:Macro>
    </asp:Content>

    languageredirectcontrol.ascx:

    <%@ Control Language="C#"  %>

    <script runat="server">
       
           
    public string DefaultLanguage { get; set; }

           
    public System.Collections.Generic.IList<string> Languages { get; set; }

           
    protected override void OnInit(EventArgs e)
           
    {
                base
    .OnInit(e);
               
    var preferredLanguage = "";
               
    if (Page.Request.Cookies["preferredLanguage"] != null)
               
    {
                    preferredLanguage
    = Page.Request.Cookies["preferredLanguage"].Value;
                   
    if (!String.IsNullOrEmpty(preferredLanguage))
                   
    {
                       
    Response.Redirect("/" + preferredLanguage);
                   
    }
               
    }
               
    var cookie = new HttpCookie("preferredLnguage");
                cookie
    .Expires = DateTime.Now.AddMonths(1);
               
    var redirectLanguage = "";
               
    if (Page.Request.UserLanguages != null)
               
    {
                    foreach
    (string language in Page.Request.UserLanguages)
                   
    {
                       
    if (language.Substring(0, 2).Equals("nl"))
                       
    {
                            redirectLanguage
    = "nl";
                           
    break;
                       
    }
                       
    if (language.Substring(0, 2).Equals("en"))
                       
    {
                            redirectLanguage
    = "en";
                           
    break;
                       
    }
                       
    else if (language.Substring(0, 2).Equals("fr"))
                       
    {
                            redirectLanguage
    = "fr";
                           
    break;
                       
    }
                   
    }
               
    }
               
    if (!string.IsNullOrEmpty(redirectLanguage))
               
    {
                    cookie
    .Value = redirectLanguage;
                   
    Response.Cookies.Add(cookie);
                   
    Response.Redirect("/" + redirectLanguage);
               
    }

               
    var defaultLanguage = System.Configuration.ConfigurationSettings.AppSettings["DefaultLanguageRedirect"];
               
    if (!String.IsNullOrEmpty(defaultLanguage))
               
    {
                   
    Response.Redirect(defaultLanguage);
               
    }
               
    Response.Redirect("/nl");
           
    }

    </script>

    The code above also checks if a cookie exists with a user language choice, should he be a returning visitor, it's possible to save the language preference of the visitor should he prefer a different language as his browser preference. This does require additional code for the " language switch" button that you use.

    In the content section, we create this structure:

    Where we set the locale for the NL and FR pages. All other content is created below these pages (except mayby a custom 404 error, and googlesitemap.xml file for SEO)

    For the NL and FR (and other languages) i also set the locale using the "manage hostnames" menu in the context menu of the page:

    Detail of the hostname configuration for the dutch version of the website:

     

    The benifit of setting the language this way, is that you can start using dictionary items in your templates and xslt files etc, I also recommend creating a dictionary item "language" with the short keys "en;fr;nl;" in them, so you can test against these columns in xslt in choice statements, to run different queries depening on language

  • Jacob 39 posts 88 karma points
    Nov 15, 2010 @ 14:44
    Jacob
    0

    I have tried this, and I got to the part where I was send to the right url umbraco.test/da

    My problem is if I call http://umbraco.test/da.aspx I get the content shown which I was expecting, but if I call http://umbraco.test/da I get a 404 error.

    If I look under properties on the folder da, I see Alternative link, http://umbraco.test/da can anybody point me to what im doing wrong?

  • Rik Helsen 670 posts 873 karma points
    Nov 17, 2010 @ 09:28
    Rik Helsen
    0

    In your web.config, update:

        <add key="umbracoUseDirectoryUrls" value="true" />

     

  • Jacob 39 posts 88 karma points
    Nov 17, 2010 @ 11:08
    Jacob
    0

    Thanks for the reply, but it did not fix the problem, I still get 404 error with the settings set to true.

    Im using IIS7, I do not know if that can make a difference.

  • Rik Helsen 670 posts 873 karma points
    Nov 19, 2010 @ 13:11
    Rik Helsen
    0

    change the application pool mode to integrated

  • Arnold Visser 418 posts 778 karma points hq c-trib
    Nov 19, 2010 @ 14:13
    Arnold Visser
    0

    Read the information on this page:

    http://learn.iis.net/page.aspx/508/wildcard-script-mapping-and-iis-7-integrated-pipeline/

    I think you need to add wildcard script mapping to be able to load the extentionless url's.

  • Jacob 39 posts 88 karma points
    Nov 22, 2010 @ 12:48
    Jacob
    0

    Hey Rik

    Thanks it worked when I enabled integrated mode on the app pool.

  • Sjors Pals 617 posts 270 karma points
    Nov 22, 2010 @ 14:09
    Sjors Pals
    0

    Make sure that if your content is available under multiple domainnames/url's that you use link/canonical tag: http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html

Please Sign in or register to post replies

Write your reply to:

Draft