{"id":51,"date":"2005-12-08T13:48:03","date_gmt":"2005-12-08T16:48:03","guid":{"rendered":"http:\/\/www.sysop.ca\/?p=51"},"modified":"2018-10-01T06:30:26","modified_gmt":"2018-10-01T13:30:26","slug":"using-apache-mod_rewrite-to-support-multiple-subdomains-in-the-same-virtual-host","status":"publish","type":"post","link":"http:\/\/www.sysop.ca\/?p=51","title":{"rendered":"Using apache mod_rewrite to support multiple subdomains in the same virtual host"},"content":{"rendered":"<p>Here&#8217;s a trick for redirecting multiple subdomains like sub.domain.tld to www.domain.tld\/sub. <\/p>\n<p>        ServerAdmin webmaster@servername.tld<br \/>\n        DocumentRoot  \/home\/www\/domain.tld\/html<br \/>\n        DirectoryIndex  index.php index.htm index.html<br \/>\n        ServerName domain.tld<br \/>\n        ServerAlias www.domain.tld<br \/>\n        ServerAlias subdomain1.domain.tld<br \/>\n        ServerAlias subdomain2.domain.tld<br \/>\n        RewriteEngine On<br \/>\n        RewriteCond %{HTTP_HOST} ^subdomain1\\.domain\\.tld$ [NC]<br \/>\n        RewriteRule ^(.*)$ http:\/\/www.domain.tld\/subdomain1$1 [R=301,L]<br \/>\n        RewriteCond %{HTTP_HOST} ^subdomain2\\.domain\\.tld$ [NC]<br \/>\n        RewriteRule ^(.*)$ http:\/\/www.domain.tld\/subdomain2$1 [R=301,L]<\/p>\n<p>This comes in handy if you want to support multiple subdomains in the same apache virtual host. All the subdomain pages can then be stored under DocumentRoot without creating different virtual hosts. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a trick for redirecting multiple subdomains like sub.domain.tld to www.domain.tld\/sub. ServerAdmin webmaster@servername.tld DocumentRoot \/home\/www\/domain.tld\/html DirectoryIndex index.php index.htm index.html ServerName domain.tld ServerAlias www.domain.tld ServerAlias subdomain1.domain.tld ServerAlias subdomain2.domain.tld RewriteEngine On RewriteCond %{HTTP_HOST} ^subdomain1\\.domain\\.tld$ [NC] RewriteRule ^(.*)$ http:\/\/www.domain.tld\/subdomain1$1 [R=301,L] RewriteCond %{HTTP_HOST} ^subdomain2\\.domain\\.tld$ [NC] RewriteRule ^(.*)$ http:\/\/www.domain.tld\/subdomain2$1 [R=301,L] This comes in handy if you want to support multiple &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.sysop.ca\/?p=51\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using apache mod_rewrite to support multiple subdomains in the same virtual host&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-unix"],"_links":{"self":[{"href":"http:\/\/www.sysop.ca\/index.php?rest_route=\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.sysop.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sysop.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sysop.ca\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sysop.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=51"}],"version-history":[{"count":1,"href":"http:\/\/www.sysop.ca\/index.php?rest_route=\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":460,"href":"http:\/\/www.sysop.ca\/index.php?rest_route=\/wp\/v2\/posts\/51\/revisions\/460"}],"wp:attachment":[{"href":"http:\/\/www.sysop.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sysop.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sysop.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}