Search

I'm building a website for a client. They have many locations in cities around the country. They want a main corporate site, with subdomains for each location. (e.g. newyork.clientsite.com). They also want to be able to create new location sites on the fly. I was thinking of having the subdomains pull content from pages on the syphony site.

For example: "newyork.clientsite.com" pulls content from "clientsite.com/location/newyork/"

I have enabled wildcard domains for this purpose. They currently use Wordpress multisite for this, but it's messy. Any help or suggestions are much appreciated. Has anyone else needed something like this?

Take a loot at the URL Router extension to see how "page routes" can be done in an extension. However, I think that your case is not covered by this extension, because you want to have routes based on the subdomain. So you might think about creating your own extension.

Let's keep it simple — I think .htaccess should do it. Something like:

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/location/%1/$1 [R=301,L]

I have not tested this, but it should give at least you a start. Place these line before the Symphony rules in the htaccess file.

Thanks michael-e.

I gave this a whirl and have been tinkering with a variation of this for a day now. I end up getting redirect loops.

The other issue is that I don't want to redirect to example.com/location/newyork/, I just want to serve up content from there to a URL like newyork.example.com.

Any thoughts?

My main goals are to be able to manage all of the subdomains from a single symphony installation and allow creation of new location subdomains on the fly.

If you don't want it to redirect, take out the R=301 from Michael's example.

You shouldn't be experiencing redirect loops with that ruleset. Can you post an example of what the browser's address bar is when it reports a redirect loop?

I finally figured it out! The redirect loops were a result of the a conflict with the Symphony frontend rewrite rule.

I added the following just above the Symphony frontend rewrite rules.

RewriteCond %{REQUESTFILENAME} !-d RewriteCond %{REQUESTFILENAME} !-f RewriteCond %{HTTPHOST} ^([^.]+).example.com$ [NC] RewriteRule ^(?!page/) page/%1%{REQUESTURI} [L,NC]

RewriteCond %{HTTP_HOST} ^([^.]+).example.com$ [NC] RewriteRule ^(?!page)$ page/%1 [NC]

Here's what it allows me to do: "->" indicates "delivers content from"

subdomain.example.com -> example.com/page/subdomain subdomain.example.com/subpage/ -> example.com/page/subdomain/subpage subdomain.example.com/symphony/ -> example.com/symphony/ nonexistant-subdomain.example.com -> example.com(404 page)

Everything works perfectly!

Glad to hear it!

@mlathrom can you check whether the following works in place of your ruleset?

### FRONTEND SUBDOMAIN REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^([^.]+)\.([^.]+)\. [NC]
RewriteRule ^(.*\/?)$ index.php?symphony-page=page/%1/$1&%{QUERY_STRING} [L]

### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ index.php?symphony-page=$1&%{QUERY_STRING}   [L]

I've included the frontend rewrites for clarity of position in the .htaccess. The benefits of the above would be that you could have more than just the subdomain as a parameter. You could have subdomains with pseudo pages, being second and third parameters for the 'page'.

Forgot to mention...

Also, redirecting to the Symphony index.php file saves another loop through all the rules, which your example would do.

That didn't seem to work, but it put me on the right path. Here's what I came up with.

    ### FRONTEND SUBDOMAIN REWRITE - Will ignore files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^([^.]+)\.([^.]+)\.([^.]+)$ [NC]
RewriteRule ^(?!about) index.php?symphony-page=about/%1%{REQUEST_URI}&%{QUERY_STRING} [L]

### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ index.php?symphony-page=$1&%{QUERY_STRING} [L]

Thanks for posting the version that works! This is going to be super useful.

No problemo :) I'm developing a site with this right now. I haven't run into any issues yet. I can still debug, images aren't broken, url parameters work fine. I'll provide an update and link to the website once I've completed so you can see how it works.

Nice!

Hello there,

I'm also building a site with subdomain. Thanks to this post I've been able to set the redirection (my site is multilingual so I had to change a few things ).

The issue I now have, is that I can not find the member info in my params when i'm accessing the page with the subdomain adress. The member-login-info event return logged-in="no".

I guess this have something to do with the cookie associated with the wrong domain but I don't have a clue on how to solve this issue.

mlathrom, have you had the same problem with your site ?

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details