Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2010-07-08 04:34:45
- eric2007
- Member
- Registered: 2006-05-25
- Posts: 18
How do I map sections to subdomains?
So, I’m back on Textpattern after a hiatus with Wordpress, which is still a kludge for designing sites despite having 98% market penetration and a gajillion plugins. So, yay!
Anyway: I have textpattern set up at mysite.com. So my cats section is at mysite.com/cats.
How can I make cats.otherdomain.com point to mysite.com/cats?
I am on Dreamhost, so I don’t have my own server or anything. In the control panel I can tell a subdomain to point to a directory but I can’t point it to mysite.com/cats/ because it’s not a real directory but a clean url. There is also an option to mirror a site, but only a domain or subdomain can be mirrored.
Is there a way to do this?
It would be great if the links on the mysite.com/cats version could point to mysite.com/cats/x and the links on cats.otherdomain.com could point to cats.otherdomain.com/x, but I could live without that.
Offline
Re: How do I map sections to subdomains?
Can’t you do this with .htaccess redirects? I’m pretty sure Dreamhost gives you access to your .htaccess file.
In any case, I don’t think the solution will be something you do via Textpattern.
Offline
Re: How do I map sections to subdomains?
Hi eric2007.
I’ve done this, and you are lucky, I’ve done it on a client’s site hosted at Dreamhost, on a basic plan (if I’m not wrong).
The key here is to set a reverse proxy. More precisely, I did it using a PHP Reverse Proxy, as the basic Dreamhost plan doesn’t allow you to set an Apache Reverse Proxy (if you would like to, you will have to switch to a better plan, I think it’s called “DV” or something like that).
So, you will need:
- an PHP Reverse Proxy script. I’ve used this: php5rp
- if you use that one, be sure to patch it as per this reported issue. It’s the only way to make it work on a basic DH plan. Look for my comment (maniqui) at the end of issue 4.
- to make things easier for you, here is an already patched version of php5rp, where I’ve also fixed this other issue (a typo)
So, some quick instructions which I can refine later if you have any problem understanding them:
- create/setup your subdomain, and its public folder (the one accesible via a web browser)
- on your subdomain public folder,
- create an
index.php
files and a.htaccess
file - create a
/php5rp/
folder with the php5rp files.
- create an
- inside the
/php5rp/
folder, create aconfig.php
file.
You are almost done. This are the contents of each file:
/index.php
:
<?php
if (!defined('php5rp_path'))
{
define("php5rp_path", dirname(__FILE__).'/php5rp');
}
include php5rp_path.'/config.php';
include_once $php5rp['php5rp_path'].'/ProxyHandler.class.php';
$proxy = new ProxyHandler($php5rp['public_site_url'],$php5rp['private_site_url']);
$proxy->execute();
?>
/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.+)$ index.php/$1 [QSA]
/php5rp/config.php
<?php
// The "public" domain
$php5rp['public_site_url'] = 'http://cats.otherdomain.com/';
// The "private" domain
$php5rp['private_site_url'] = 'http://www.mysite.com/cats/';
// The absolute path to the "php5rp" folder (usually something like: /home/user/cats.otherdomain.com/php5rp/
$php5rp['php5rp_path'] = '/path/to/folder/php5rp/';
?>
Well, this is the first time I share this trick. Let me know if it worked for you (hopefully!).
Also, for others reading this post: this trick opens the possibility of managing a bunch of microsites from one TXP install, but serve them from different domains. If your client ask you to create a new (very basic) site for him on a new domain, this may be the chance to avoid having a new TXP install running, and hopefully, makes your client love you (even more), not only for using TXP on his site(s) but for letting him maintain both sites from one TXP install.
Also, this doesn’t apply just to categories, but probably to any TXP url. You could make a new microsite by pointing the PHP Reverse Proxy to a section, a category, an article permalink, etc.
BTW, eric2007, good to see someone coming back from WP. Here, you are able to write Textpattern as you like: TXP, Txp, txp, TextPattern, Textpattern, Text pattern, test pattern, TP, Texpatter. No one is gonna impose you anything, like there at WP universe.
Offline
#4 2010-07-08 17:44:23
- eric2007
- Member
- Registered: 2006-05-25
- Posts: 18
Re: How do I map sections to subdomains?
This is amazing! Thank you so much, maniqui! I am sure many others will use this as well.
It works perfectly. The only problem I’m having is that other URLs inside the cat section don’t work. I can’t access cats/post at cats.otherdomain.com/post—the page says “No input file specified.” Nonexistent URLs give back “No input file specified” as well, instead of using my error_default page.
Is there a way to keep Textpattern’s other URLs working with this?
Offline
Re: How do I map sections to subdomains?
Weird, as it works for me, both on my local setup and on DH. If possible to share, what’s the website public URL?
Offline
#6 2010-07-09 03:14:17
- eric2007
- Member
- Registered: 2006-05-25
- Posts: 18
Re: How do I map sections to subdomains?
One of my attempts is here: http://bit.ly/9UzC9c
• Textpattern is at myurl.com/new/
• The section I want is at myurl.com/new/test/
• The subdomain where I want it to appear is my.myurl.com
I have a post up called “Hello.”
The problem is that while myurl.com/new/test/hello works, my.myurl.com/hello does not (nor does textpattern’s default 404 page).
The content of config.php is
<?php
// The “public” domain
$php5rp[‘public_site_url’] = ‘http://my.automaticfriend.com/’;
// The “private” domain
$php5rp[‘private_site_url’] = ‘http://www.automaticfriend.com/new/test/’;
// The absolute path to the “php5rp” folder (usually something like: /home/user/cats.otherdomain.com/php5rp/
$php5rp[‘php5rp_path’] = ‘/home/[myusername]/my.automaticfriend.com/php5rp/’;
?>
Last edited by eric2007 (2010-07-09 03:14:46)
Offline
Re: How do I map sections to subdomains?
Have you created an .htaccess on the document root of my.automaticfriend.com?
Also, could you test by changing the private_site_url setting to:
http://www.automaticfriend.com/new/
And then pointing brower too
‘http://my.automaticfriend.com/test/
and see if that one works (and also, check any URL under /test/?
This is just to prove if it may work with other URL.
Offline
Re: How do I map sections to subdomains?
Also, which are the PHP settings for your subdomain? (you can check them on DH control panel)
PHP5 FastCGI? PHP5 CGI? mod_security is enabled?
Offline
#9 2010-07-09 04:06:07
- eric2007
- Member
- Registered: 2006-05-25
- Posts: 18
Re: How do I map sections to subdomains?
Nope, URLs still don’t work with the private_site_url set to new.
The .htaccess file is what you posted above:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.+)$ index.php/$1 [QSA]
—and it’s in home/user/my.automaticfriend.com/ along with index.php and the php5rp/ folder containing config.php and ProxyHandler.class.php.
Last edited by eric2007 (2010-07-09 04:07:26)
Offline
Re: How do I map sections to subdomains?
I suggest you to toy with PHP settings for the subdomain (and maybe for the main domain too), and see if things start to work properly.
You can also try by changing the last line in .htaccess to:
RewriteRule ^(.+)$ index.php?/$1 [QSA]
Offline
#11 2010-07-09 04:09:30
- eric2007
- Member
- Registered: 2006-05-25
- Posts: 18
Re: How do I map sections to subdomains?
ps. How do you highlight code in the forum? Nothing happened when I added “bc..” as specified in the <a href=“http://textpattern.com/faq/?c=Forum”>FAQ</a>.
Offline
Re: How do I map sections to subdomains?
or
@some inline code@
For large blocks of codes use bc..
(two dots) and escape from the block by using p.
at the beginning of the first line followng the block code.
Offline