Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 22, 2013 @ 12:08
    Bo Damgaard Mortensen
    0

    Best approach to make a domain dependent content

    Hi all,

    One of my clients wants a "section" in the content tree where local news articles can be created by local users (from within Umbraco) The site structure is as follows:

    - Content
             - mysite.com (Current hostname: mysite.com (english))
                        - Frontpage
                        - Some text page
                        - Some text page
                        - News
                        - Local news
                                  - Danmark
                                            - News item 1
                                  - Sverige
                                            - News item 1
                                  - England
                                            - News item 1
                                  - Norge
                                            - News item 1

    Now, on the News page they want to create a link to i.e. the swedish (Sverige) local news page, but only if a user visits their site with the domain: mysite.se and not .com which is the standard site.

    What exactly would the best approach be to create this? "Problem" is that the main navigation is rendered using the mysite.com hostname which is set on the site-node in Umbraco. So if I enter the site with domain: mysite.se and I click on a menu item (i.e. the News link), I'll get "redirected" to the .com domain.

    Any input is greatly appreciated! :-) Let me know if some of the above needs to be elaborated.

    Thanks in advance.

    All the best,

    Bo

  • Stephen 767 posts 2273 karma points c-trib
    Feb 22, 2013 @ 16:30
    Stephen
    100

    First, which version of Umbraco are you going to use?

    Then... not sure I understand at that point. So you'll have page mysite.com/news which just display english news, and if I visit mysite.se/news then there should be a link to some local news in swedish eg to mysite.de/sverige.

    Which means that the entire website should be browseable via mysite.com and also via mysite.se, right? To achieve this you should define both domains on the root node, then set useDomainPrefixes to false to get relative urls everywhere. That way you will _not_ be redirected to .com, if that's what you want to avoid.

    Am I making sense?

    Stephan

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 22, 2013 @ 16:54
    Bo Damgaard Mortensen
    0

    Hi Stephen,

    Thanks a lot for your input :-)

    Yes, bottom line is that they want mysite.*/news (any mysite.xx can be used, they have a lot of domains) to list the global news from the News folder within the sites content. So if I enter the site with i.e.: mysite.se, the news page should display global news items, but I should also be able to click on a link to the swedish, local news page from there.

    The problem is that when I enter the site with mysite.se and clicks on the News link in the menu, the domain changes to mysite.com which doesn't show any link (because the domain is .com)

    So basically, the entire site should be browsable by mysite.XX and if I enter the site with mysite.se, a link will appear on the global news section to the swedish local news page.

    If I understand it correctly, all I need is to set up mysite.se (and all other mysite.XX) in the manage hostnames on my site node in Umbraco and then I should be good to go with the navigation not changing to .com? :-)

    Thanks again! Sorry if this is confusing.

    All the best,

    Bo

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 22, 2013 @ 16:55
    Bo Damgaard Mortensen
    0

    Btw, the version of Umbraco is 4.11.1 :-)

  • Stephen 767 posts 2273 karma points c-trib
    Feb 22, 2013 @ 17:05
    Stephen
    0

    @bo: in theory, yes, you would setup all your mysite.xx (porn?) domains on the root node, then ensure that useDomainPrefixes is false, and you should get relative urls within the sites => the menu urls will be "/about-us", not "mysite.com/about-us".

    Let me know how it works!

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 22, 2013 @ 17:13
    Bo Damgaard Mortensen
    0

    Hi Stephen,

    If only it were porn :-D

    I just tried to set it up like that on my localhost and it seems to work! The useDomainPrefixes setting were false by default. Only thing I find a bit dirty (no, it's still not porn..) is how to find the correct local news page to display.

    The way I do it now is like this:

    On every country-node (i.e. Denmark) I have a textstring field where the administrator can enter the domain extension that should be used to find the link. I.e. if he enters .dk the macro on news overview will parse the current domain and finde that folder. Code for parsing looks like this:

    public static Node GetLocalNewsPageLink()
            {
                try
                {
                    // Get a reference to the current request
                    var request = HttpContext.Current.Request;
    
                    // Get the current domain extension
                    string domainExt = request.Url.Host.Substring(request.Url.Host.LastIndexOf('.'));
    
                    // Get a reference to the local news page where the domain extension matches
                    var localNewsPage =
                        uQuery.GetNodesByType("LocalNewsPage").FirstOrDefault(x => !string.IsNullOrEmpty(x.GetProperty("domainExtension").Value) && x.GetProperty("domainExtension").Value.Equals(domainExt));
    
                    // Return the url for the local news page if the variable is not null
                    return localNewsPage ?? null;
                }
                catch (Exception)
                {
                    return null;
                }
            }

    I'm wondering if there would be a more clean way to do this? Would certainly be a more clean solution to check on the hostname set in Umbraco, but since all hostnames are set on the site node, this is not an option.

    Thanks again! :-)

  • Stephen 767 posts 2273 karma points c-trib
    Feb 22, 2013 @ 17:21
    Stephen
    0

    Ok, no porn then ;-)

    As you rightfully point out, you cannot register a domain on the local news node. So you have to create an extra property on those nodes to store the ".dk" extension which will allow you to decide which one to display, if any.

    There is another solution but I can't tell if it will work in 4.11.1. It should in 4.11.4/5 but... OK. You will have to test. Starting with 4.11.? you can register "wildcard" domains on a node, that just change the culture for that node and down under. To create a wildcard domain, you just create a normal domain but set the domain name to "*" (a star).

    So you could create wildcard domains on each local news node. To figure out if a node should be displayed, look at the domains defined on the node, check if one is a wildcard domain, check if the culture of that domain matches the current culture.

    Nice, but a bit experimental. I know for sure how to do it in 6.x but dunno it's going to be simple in 4.x -- maybe you'll want to stick with your proved solution.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 22, 2013 @ 17:31
    Bo Damgaard Mortensen
    0

    Actually, the wildcard did work in Umbraco ver. 4.11.1 :-) Didn't know you could simply put a * there, awesome!

    I like the solution, it's better than having a textstring field for storing the domain extension. However, I'm not sure I want the administrators to mess around with setting up hostnames - it seems a bit more low-tech to simply enter .se in a textfield ;-)

    I'll see what solution I'll go with.

    Thanks a lot for your help Stephen! Hero of the day :-D

  • Stephen 767 posts 2273 karma points c-trib
    Feb 22, 2013 @ 17:33
    Stephen
    0

    The wildcard stuff is one step in the path to separate hostnames and cultures. Brand new ;-)

    Glad it works.

Please Sign in or register to post replies

Write your reply to:

Draft