System Administrator Jahia 7.3 Jahia 8

One FQDN to rule them all

Question

Is it possible to use one fully qualified domain name (FQDN) for multiple websites?

Answer

While Jahia supports one FQDN per website, it is possible to workaround that thanks to the use of URL rewrite rules at the front-end and Jahia levels BUT before going on this road, you should consider the following:

  • This kind of scenario is not supported by Jahia so it's not being tested for new releases or new products
  • Any new modification to the rewrite rules can have unforeseen side effects so it's strongly advised to have an automatic test suite to prevent any regression

The current scenario:

  • Two FQDNs: www.company1.com and www.company2.com
  • For each FQDN, three websites:
    • a "global" one, accessible through the URL https://<FQDN>/global/en/
    • two sub-sites, accessible through the URL:
      • https://<FQDN>/site1/en/
      • https://<FQDN>/site2/en/
  • The websites need to be configured this way:
    screenshot_104.png
    • each website of a company has:
      • a site key starting by the "company key" then with the site key
      • a server name starting by the site key then with the domain name. The server name has to be resolved, at least at the front-end level
  • HAProxy is being used at the front-end level (version 2.0.13-2)

Steps to follow:

 

  • Update your HAProxy configuration with the following configuration:
    defaults
     log global
     mode http
     option httplog
     option dontlognull
            option  httpclose
     retries 3
            timeout connect 300
            timeout client  1200s
            timeout server  1200s
            option http-server-close
            option forwardfor
    
    
    frontend http_front
            bind *:80
            redirect scheme https code 301 if !{ ssl_fc }
    
    frontend https_front
            bind *:443 ssl crt /etc/haproxy/key_and_cert.pem
            reqadd X-Forwarded-Proto:\ https
            default_backend https_back
    
    #Production v1.0.16
    #dns list
    acl dns_www.company1.com hdr(host) -i www.company1.com
    acl dns_www.company2.com hdr(host) -i www.company2.com
    
    acl rootpath path_reg ^/$|^/global/$|^/global/..$
    
    #language
    acl language_en req.fhdr(accept-language),language(fr;en) -m str en
    acl language_fr req.fhdr(accept-language),language(fr;en) -m str fr
    
    #/modules/forms
    acl forms path_reg ^/.*modules/forms/.*$
    
    #redirect back
    #redirects to company1 corporate website
    http-request redirect code 301 location https://www.company1.com/global/fr/ if dns_www.company1.com rootpath language_fr 
    http-request redirect code 301 location https://www.company1.com/global/en/ if dns_www.company1.com rootpath
    
    #http-request replace-uri ^/([a-z]{2})/sites/company1_([^/]+)(/.*)$ /\2/\1\3 if dns_www.company1.com
    #http-request replace-uri ^/([a-z]{2})/sites/company1_([^/]+)(/.*)$ /global/en/home/about/ if dns_www.company1.com
    
    #redirects to company2 corporate website
    http-request redirect code 301 location https://www.company2.com/global/fr/ if dns_www.company2.com rootpath language_fr 
    http-request redirect code 301 location https://www.company2.com/global/en/ if dns_www.company2.com rootpath
    
    
    #rewrites maybe use http-request set-path
    http-request replace-uri ^/(?!cms)(.*?)/([a-z]{2})/(.*) /\2/sites/company1_\1/home/\3 if dns_www.company1.com
    http-request replace-uri ^/(?!cms)(.*?)/([a-z]{2})/(.*) /\2/sites/company2_\1/home/\3 if dns_www.company2.com
    
    #set header for using right template
    acl site_company1 hdr(host) -i www.company1.com
    acl site_company2 hdr(host) -i www.company2.com
    http-request set-header shared-site company1 if site_company1
    http-request set-header shared-site company2 if site_company2
    ## Header sub-site
    http-request set-header sub-site %[capture.req.uri] if !forms
    http-request set-header sub-site %[hdr(referer)] if forms
    http-request replace-header sub-site ^https?://[^/]*(/[^/]*/[^/]*/.*)$ \1 if forms
    http-request replace-header sub-site ^/([^/]*)/?.*$ \1
    
    ## Header language
    http-request set-header sub-site-language %[capture.req.uri] if !forms
    http-request set-header sub-site-language %[hdr(referer)] if forms
    http-request replace-header sub-site-language ^https?://[^/]*(/[^/]*/[^/]*/.*)$ \1 if forms
    http-request replace-header sub-site-language ^/[^/]*/?([^/]*)/?.*$ \1
    
    ## Set the header host in order to activate the SEO for the correct website
    http-request set-header Host %[req.hdr(sub-site)].company1.com if dns_www.company1.com !forms
    http-request set-header Host %[req.hdr(sub-site)].company2.com if dns_www.company2.com !forms
    
    
    backend https_back
            compression algo gzip
            compression type text/plain text/css text/js text/xml text/javascript application/javascript application/json application/xml application/rss image/svg text/html
            server jahia1 127.0.0.1:8080 check fall 1 rise 1 inter 2s 
            balance leastconn
     http-request set-header X-Forwarded-Port %[dst_port]
            http-request add-header X-Forwarded-Proto https if { ssl_fc }
     http-request add-header X-CLIENT-IP %[src]

     

  • Install a custom module (in our case multi-sites-rewriting) with two URL rewrite rules files (cf this generic documentation):
  • Set the property urlRewriteUseAbsoluteUrls to false in the file JAHIA_HOME/digital-factory-config/jahia/jahia.properties
  • Flush completely your Internet browser cache

 

Known issues:

  • SEO URLs are not working always as expected
  • Link to a page on another website does is incorrect