{"id":3446,"date":"2017-03-14T12:22:25","date_gmt":"2017-03-14T11:22:25","guid":{"rendered":"https:\/\/florianbrinkmann.com\/en\/?p=3446"},"modified":"2020-02-09T11:36:20","modified_gmt":"2020-02-09T10:36:20","slug":"wordpress-multisite-mix-of-subdomains-and-subdirectories","status":"publish","type":"post","link":"https:\/\/florianbrinkmann.com\/en\/wordpress-multisite-mix-of-subdomains-and-subdirectories-3446\/","title":{"rendered":"WordPress multisite with a mix of subdomains and subdirectories"},"content":{"rendered":"<p>While setting up multisite, you decide to use either subdomains or subdirectories \u2014 mixing both in one multisite is not possible without modifications. This post shows you how to run a multisite with subdomains and subdirectory sites.<!--more--><\/p>\n<p>I recently moved my site from <code class=\"lang-markup\">.de<\/code> to <code class=\"lang-markup\">.com<\/code> and the English version from <code class=\"lang-markup\">en.florianbrinkmann.com<\/code> to <code class=\"lang-markup\">florianbrinkmann.com\/en<\/code>. The problem: besides the English and German site, the demos of my WordPress themes are also part of the multisite, and they should stay on their subdomains. So I needed a mix from subdomains and subdirectory in one multisite.<\/p>\n<p>Luckily I am not the first with this problem, and while searching for a solution, I found the posts <a href=\"http:\/\/dnaber.de\/blog\/2015\/wordpress-multisite-sub-domains-und-sub-directories-kombinieren\/\">\u00bbWordPress Multisite: (Sub-)Domains und Sub-Directories kombinieren\u00ab by David Naber<\/a> and <a href=\"http:\/\/toscho.de\/2013\/wordpress-multisite-mit-mehreren-domains\/\">\u00bbWordPress Multisite mit mehreren Domains einrichten\u00ab by Thomas Scholz<\/a>, which were very helpful.<\/p>\n<p>These are the steps I made for changing the structure of my site (starting from a multisite which is set up for subdomains):<\/p>\n<ol>\n<li>Inserting <code class=\"lang-php\">define( 'NOBLOGREDIRECT', 'https:\/\/example.com' );<\/code> into <code class=\"lang-markup\">wp-config.php<\/code> to disable registration of new sites via the frontend. Perhaps you need to write <code class=\"lang-php\">remove_action( 'template_redirect', 'maybe_redirect_404' );<\/code> into the theme\u2019s <code class=\"lang-php\">functions.php<\/code> or (better) into a (MU) plugin, <a href=\"https:\/\/wordpress.org\/support\/topic\/404-page-not-working-after-setting-noblogredirect\/#post-4844131\">to prevent the site from redirecting 404 errors to the main domain<\/a>.<\/li>\n<li>Defining the following constants in <code class=\"lang-markup\">wp-config.php<\/code>:\n<pre class=\"lang-php\"><code class=\"lang-php\">define( 'ADMIN_COOKIE_PATH', '\/' );\ndefine( 'COOKIEPATH', '' );\ndefine( 'SITECOOKIEPATH', '' );<\/code><\/pre>\n<p>Without this code, you would have to log in into the subdirectory site(s), also if you are already logged in into the main site or a subdomain site. The starting point for this solution were the linked articles and an <a href=\"https:\/\/wordpress.org\/support\/topic\/how-to-do-domain-mapping-in-wp45-without-plugin\/#post-7390818\">answer in the WordPress.org forum<\/a>.<\/p><\/li>\n<li>Modify WordPress\u2019 rewrite rules inside the <code class=\"lang-markup\">.htaccess<\/code>, so they match the rules of subdirectory installations, to let you access the backend of your subdirectory install:\n<pre class=\"language-bash\"><code class=\"language-bash\">RewriteEngine On\nRewriteBase \/\nRewriteRule ^index\\.php$ - [L]\n# add a trailing slash to \/wp-admin\nRewriteRule ^wp-admin$ wp-admin\/ [R=301,L]\nRewriteCond %{REQUEST_FILENAME} -f [OR]\nRewriteCond %{REQUEST_FILENAME} -d\nRewriteRule ^ - [L]\nRewriteRule ^([_0-9a-zA-Z-]+\/)?(wp-(content|admin|includes).*) $2 [L]\nRewriteRule ^([_0-9a-zA-Z-]+\/)?(.*\\.php)$ $2 [L]\nRewriteRule . index.php [L]<\/code><\/pre>\n<\/li>\n<li>Create a new site in your multisite (it does not matter which subdomain you choose).<\/li>\n<li>Open the site\u2019s information and enter the main domain with the subdirectory. Until a few WordPress versions, there was an extra field for the path.<noscript><img decoding=\"async\" class=\"alignnone size-full wp-image-3447\" src=\"https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting.png\" alt width=\"818\" height=\"562\" srcset=\"https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting.png 818w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting-291x200.png 291w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting-300x206.png 300w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting-768x528.png 768w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting-806x554.png 806w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting-600x412.png 600w\" sizes=\"(max-width: 818px) 100vw, 818px\"><\/noscript><img decoding=\"async\" class=\"alignnone size-full wp-image-3447 lazyload\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20818%20562%22%3E%3C%2Fsvg%3E\" alt width=\"818\" height=\"562\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20818%20562%22%3E%3C%2Fsvg%3E 818w\" sizes=\"(max-width: 818px) 100vw, 818px\" data-srcset=\"https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting.png 818w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting-291x200.png 291w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting-300x206.png 300w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting-768x528.png 768w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting-806x554.png 806w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting-600x412.png 600w\" data-src=\"https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2017\/03\/multisite-domain-setting.png\"><\/li>\n<li>Done. \ud83c\udf89<\/li>\n<\/ol>\n<p>If you are switching a site from a subdomain to a subdirectory like I did, remember to create redirects! You can find example code for redirecting a subdomain to a subdirectory on Stack Overflow.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While setting up multisite, you decide to use either subdomains or subdirectories \u2014 mixing both in one multisite is not possible without modifications. This post shows you how to run a multisite with subdomains and subdirectory sites.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wpf_show_in_dewp_planet_feed":false,"flobn_post_versions":"","webmentions_disabled_pings":false,"webmentions_disabled":false,"lazy_load_responsive_images_disabled":false,"footnotes":""},"categories":[115],"tags":[],"class_list":["post-3446","post","type-post","status-publish","format-standard","hentry","category-wordpress-snippets"],"wp-worthy-pixel":{"ignored":false,"public":"7f6f82a13ae24c63966234bc33ab439d","server":"vg07.met.vgwort.de","url":"https:\/\/vg07.met.vgwort.de\/na\/7f6f82a13ae24c63966234bc33ab439d"},"wp-worthy-type":"normal","_links":{"self":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/comments?post=3446"}],"version-history":[{"count":5,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3446\/revisions"}],"predecessor-version":[{"id":5979,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3446\/revisions\/5979"}],"wp:attachment":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/media?parent=3446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/categories?post=3446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/tags?post=3446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}