19

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.

4 Answers 4

12

Update for Craft 3

Craft 3 includes native support for multi-site installation. Here's a link to the official docs and here's a link to another question with more resources.

Old answer for Craft 1 & 2

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 }}

While this isn't an end all solution, it is a functional workaround, especially if it's only for page or two. Use Craft 3 if you can.

4
  • 1
    Simon, how do I add the subdomain to automatically generated links from a (redactor) rich text field? Is this possible?
    – carlcs
    Jun 12, 2014 at 7:07
  • Short of manually editing the links I don't know of any good options. Jun 12, 2014 at 19:01
  • try putting {siteUrl} into the craft config? glui.me/?i=ao3ste0jh061kdj/2014-06-16_at_3.49_pm.png Jun 16, 2014 at 7:50
  • I don't see what that would do as Craft would still have no idea what sections load at what URLs. Jun 16, 2014 at 21:00
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.

2
  • 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. Jun 12, 2014 at 10:45
  • Found the multiple subdomain feature extremely useful for making a dev.site.
    – Matteo
    Aug 20, 2015 at 18:04
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

3
  • 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. Jun 12, 2014 at 3:24
  • My mistake. I misunderstood the question. :)
    – tnypxl
    Jun 13, 2014 at 13:31
  • @tynpxl, I found your answer very helpful. My interpretation of the original question was exactly like yours.
    – PKHunter
    Aug 9, 2017 at 16:40
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.