Hello all. Prepare for a book here. It's longer than I anticipated.
Using Revolution (2.2.4-pl) I recently started developing a redesign based on an existing site on Evolution (1.0.4). Long before I got to this point, I knew I wanted to utilize contexts in Revolution. In all of the research I did in implementing contexts, most everything seemed to be about a different implementation I was looking for – until I found this thread.
After spending a little time understanding the suggestions in a post by user "bitbox"
I was able to engineer a method to achieve what I was after.
The existing site that I am working from has several "versions" using what we'll call "pseudo-subdirectories". I use this term as there are no physical directories, but friendly URLs based on the document structure in the site tree. Each version is intended for users based in a different locale. Example site tree:
+-- Site Start
+-- United States (us)
+-- Canada (ca)
+-- Puerto Rico (pr)
Each country has it's own Modx container (alias in parenthesis above) and is accessed by using the URLs: www.domain.com/us, www.domain.com/ca, www.domain.com/pr. I also have created a built-in redirection using GeoIP to direct users to the proper "version". This is in the form of a Snippet which is called from the document "Site Start".
I want to follow the same structure in the site tree for Revolution, but keep each countries version within it's own context. While this all might sound similar to those using Babel for multi-lingual sites, the difference is that only the content differs from site to site. I am using English as the language across the board.
I learned that making this work with with Revolution could be done in a number of different ways. I think I spent enough time to figure out a solid approach while taking into account the factors of complexity in configuration, analytics, search engine optimization, etc.
Here is a conceptual flow for ways the site would be accessed:
- Visitor accesses site at root level: "www.domain.com"
- Touches file ".htaccess", no rules for this, redirected to "index.php?q=$1"
- Touches file "index.php" and loads site at default context (web)
- Touches custom plugin for routing traffic, no rules for this, redirected to site start document for context "web"
- Loads site start document for context "web".
- Document is configured as "Weblink", redirected to site start document for context "us"
- Visitor accesses site at location specific level: "www.domain.com/us"
- Touches file ".htaccess", specific rules for path "/us", redirected to "index.php?c=$1&q=$2"
- Touches file "index.php?c=us" and loads site at default context (web)
- Touches custom plugin for routing traffic, specific rules for country "us", switches to context "us"
- Loads site start document for context "us"
So, what did I have to create/modify?
- Apache file for site/virtual host (required for using GeoIP, optional otherwise)
- Apache file ".htaccess"
- Modx Contexts for each unique site
- Custom Modx snippet for routing traffic to contexts
That's it. I didn't have to create physical directories or duplicate any aspect of Modx. The real magic happens with the ".htaccess" file and the custom snippet I created.
This method can also be used with multiple top-level domains, independent or simultaneously of the "pseudo-subdirectories".
[ed. note: thomasgrant last edited this post 7 years, 11 months ago.]