Topic: Multiple domains with 0.9.6  (Read 2590 times)

Pages: [1]   Go Down

#1: 2-Apr-2009, 09:16 AM


maclonghorn
Posts: 123

WWW
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/widgets

can also be reached via

superwidgets.com

I 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:
Code:
# 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.html
and turns it into something MODx can process, without changing the URL in the browser
mydomain.com/widgets/policy.html

The plugin, with OnWebPagePrerender set:
Code:
$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?

« Last Edit: 2-Apr-2009, 09:28 AM by MacLonghorn »
Mark Macatee
President
Power 10 Solutions
www.power10solutions.com

#2: 15-Apr-2009, 06:25 AM

Moderators

MadeMyDay
Posts: 966

WWW
This looks like something I really need atm ;-)

Have you more experiences with that way over the past 2 weeks?

#3: 15-Apr-2009, 08:05 AM

Testers

dev_cw
Posts: 4,218

WWW
This IS very interesting.  Cool
Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

Something is happening here, but you don't know what it is.
Do you, Mr. Jones?  -  [bob dylan]

#4: 15-Apr-2009, 09:00 AM

Moderators

MadeMyDay
Posts: 966

WWW
Seems to work... Will build my (6) sub sites and test. If this works really this simple.. another wow! moment in my MODx life. I will post a tutorial then!

#5: 1-May-2009, 05:43 AM

Olivier
Posts: 340

WWW
Great ! Thx for this add...
 Cheesy
Un site sous ModX ? > Pro-data LGI
Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.