Can I run one Craft install on multiple domains and/or subdomains?

19

8

Is it possible to have one Craft install running multiple domains and/or subdomains?

For example having the same Craft install running a blog Channel at blog.example.com and also an about Single at example.com/about.

Simon Kuran

Posted 2014-06-12T00:43:06.960

Reputation: 1 898

Answers

12

Credit to @LukeHolder for the original answer, but here's a bit more detailed and technical answer. Note, this might not be possible on all hosts.

Place the craft folder above both domains, add Craft's index.php file to both domain web roots and set the $craftPath variables in them to point to the same craft folder.

To make a template (say for a blog) only load on its own subdomain instead of whenever any of its slugs are requested on any domains you can run this quick check:

{% set domain = craft.request.getServerName() %}

{% if not domain starts with 'blog' %}
    {% redirect '404' %}
{% endif %}

This will make "blog.example.com/some-blog-post" load, but "example.com/some-blog-post" will redirect to the 404 page.

Links to posts can formatted like this to add the subdomain to the URL:

http://blog.example.com/{{ entry.uri }}

Edit: While this isn't an end all solution it is a functional workaround, especially if it's only for page or two. Accepted for now...

Simon Kuran

Posted 2014-06-12T00:43:06.960

Reputation: 1 898

try putting {siteUrl} into the craft config? http://glui.me/?i=ao3ste0jh061kdj/2014-06-16_at_3.49_pm.png/

– Luke Holder – 2014-06-16T07:50:19.360

I don't see what that would do as Craft would still have no idea what sections load at what URLs. – Simon Kuran – 2014-06-16T21:00:20.517

1Simon, how do I add the subdomain to automatically generated links from a (redactor) rich text field? Is this possible? – carlcs – 2014-06-12T07:07:03.537

Short of manually editing the links I don't know of any good options. – Simon Kuran – 2014-06-12T19:01:48.050

10

Yes, it is possible to have a Craft install on multiple domains and subdomains as long as you only access the control panel from a single domain and you only have a single installation of craft that all the domains and subdomains use.

The limitation is all domains would be using the same url router and content - although for multi language content having different domains might be the way to switch on which language to use.

Luke Holder

Posted 2014-06-12T00:43:06.960

Reputation: 4 364

Found the multiple subdomain feature extremely useful for making a dev.site. – Matteo – 2015-08-20T18:04:01.513

I'd like to see an example or tutorial for that kind of setup. Using subdomains for the locals seems to make much more sense than url segments. – Steve Adams – 2014-06-12T10:45:19.520

3

No you can't. In Craft's early days, they had a MSM-like (ala ExpressionEngine) feature, but they eventually removed because it overcomplicated the system.

You will have to run a unique craft install per domain. However, these Craft installs can at the very least share the same craft/app folder: http://buildwithcraft.com/help/sharing-craft-files

tnypxl

Posted 2014-06-12T00:43:06.960

Reputation: 79

My mistake. I misunderstood the question. :) – tnypxl – 2014-06-13T13:31:36.293

the question was asking if you can use different domains which is true, what you cant do is use the same install to run different website that have different content and url structures. See my answer below. – Luke Holder – 2014-06-12T03:24:02.230

@tynpxl, I found your answer very helpful. My interpretation of the original question was exactly like yours. – PKHunter – 2017-08-09T16:40:22.037

1

I was also looking for an elegant solution to server multiple domain from the same Craft instance and this is what I found.

The multiple domains documentation will assist your domain setup and is pretty easy: http://buildwithcraft.com/docs/multi-environment-configs

Where I got hung up is adding content which is specific to one domain. The only 'hacky' work around I could come up with was using rewrite rules (.htaccess, etc) to append the request with a url segment that could be targeted via routes.

example.com -> main site example2.com -> landing page site. .htaccess rewrites to example2.com/lp/news

In the example above, I could also access the /lp/news from blog.example.com unless I want to manage conditionals in configs / .htaccess (for this domain, not this domain, etc).

At the end of the day, it's pretty clear Craft isn't intended for multiple sites and I don't recommend solutions that become a spaghetti mess to manage. If it's a landing page or two, I think using the combination of configs, routes and rewrite rule would do the trick...anything else I would look into a separate instance.

nateiler

Posted 2014-06-12T00:43:06.960

Reputation: 174