I have a client with several products, but one in particular is their flagship product. So they needed a primary domain and a secondary domain just for the one product:
mydomain.com/widgetscan also be reached via
superwidgets.comI was able to do this by modifying the htaccess file and creating a plugin that replaces all href's with a fully-qualified domain name.
htaccess:
# This is the primary site only. It's the basic ReWrite with tests for HTTP_HOST.
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} mydomain\.com [NC]
RewriteCond %{REQUEST_FILENAME} index\.php [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# This is for the other domain.
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} index\.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(index\.(html?|php)|widgets)?(.*)$ index.php?q=/widgets/$3 [L,QSA]
The last line takes a request like
superwidgets.com/policy.htmland turns it into something MODx can process, without changing the URL in the browser
mydomain.com/widgets/policy.htmlThe plugin, with OnWebPagePrerender set:
$primary = "http://mydomain.com";
$second = "http://superwidgets.com";
if (preg_match("/superwidgets/", MODX_SITE_URL)) {
// The goal here is to prepend the full domain to every href. You need to evaluate each type of href link in your site.
// Links to anything in /assets, such as /assets/images/ or /assets/site, shouldn't need modification.
//----- superwidgets.com interior pages and any document links with relative URLs
$modx->documentOutput=preg_replace("#/?widgets/#i", $second."/", $modx->documentOutput);
//----- mydomain.com root-level pages
$modx->documentOutput=preg_replace("#\"(/[\w-]+.htm)#i", "\"".$primary."$1", $modx->documentOutput);
}
And then, since TinyMCE uses relative URLs when linking to documents in the site (see my post
http://modxcms.com/forums/index.php/topic,34502.0.html, you'll need the <base> tag in order to make the relative URLs work (need to use the [(site_url)] setting, not [(base_url)] ) This shouldn't cause a problem on the secondary site though, since every href will be fully-qualified.
The one limitation I haven't worked out yet, is this:
One thing to keep in mind (VERY IMPORTANT) is that the [(site_url)] setting, which is based on the the PHP var $_SERVER['HTTP_HOST'], can and will change as both of your sites are browsed. So if you browse to
superwidgets.com/policy.html and view source, you may very well see <base href="
http://mydomain.com/" /> and vice versa. This is why I go ahead and make every href in the secondary domain fully-qualified. So maybe the thing to do is to make every href on both domains fully-qualified?