Plugin: Vhost

As part of the Weblog Tools Collection Plugin Contest, I created a plugin that binds a virtual host to a single WordPress category.

The vhost plugin binds a WordPress category to a virtual host on your webserver, either a sub-domain or a seperate fully-qualified domain. You can have as many such bindings as you have vhosts: just make a new category for each one. Each vhost+category pair can use its own template.

You can see this in action at tangential.info, which is the main blog. The demo has been taken offline.

Additionally, blog administrators can edit a registered user's profile, and set the URL in that user's profile to the fully-qualified domain name of a valid vhost. That user may then login to http://vhost/wp-admin/ and post only in that vhost's category. If that user attempts to access the /wp-admin/ directory on the main blog, they will be redirected to their vhost.

NOTICE: This is a beta release. This plugin has not yet received extensive testing. Only download this plugin if you're willing to accept that it may break your blog. It is released with no guarantee of usability, and I will not accept any responsibility if it does bad things. I will accept bug reports and patches.

ALSO: This plugin will not work well with a default WordPress 1.5 installation. In order for post navigation to work well, you'll want to edit get_previous_post() and get_next_post() so that you can use the "in_same_category" flag. Then edit your template(s) to use previous_post_link() and next_post_link(), instead of previous_post() and next_post().
See bug 1252 and changeset 2542 for additional information.

Download vhost 1.3 now!

Mad props to Owen for his limit categories plugin, which provided an excellent foundation for me!


59 Responses to Plugin: Vhost

  1. 559 Photo Matt » Vhost Plugin 2005-04-22 22:49:04

    [...] Vhost Plugin April 22nd, 2005 3:48 pm File under: Asides “The vhost plugin binds a WordPress category to a virtual host on your webserver, either a sub-dom [...]

  2. 558 rob 2005-04-23 00:37:32

    Wow, this looks very neat. I'll definitely have a play on my home server.

  3. 557 Vix 2005-04-23 00:47:42

    I've been looking for something like this for ages! I'll let you know how it goes

  4. 556 Vix 2005-04-23 03:10:46

    What I've found so far is:

    When editing User Info at http://www.mydomain.com/wp-admin/profile.php
    I get this warning:
    Warning: parse_url(http://): Unable to parse url in /home/path/to/wp-content/plugins/vhost.php on line 136

  5. 554 Vix 2005-04-23 05:31:27

    Vhost is working fine on one server but at a different host I get this error:

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 1=1 AND post_date_gmt Server Info: PHP: 4.3.11 ; MySQL: 4.0.22 The server info where Vhost runs fine is : PHP: 4.3.10; MySQL: 4.0.23

  6. 552 networkblogger » Blog Archive » Multi Blogging with WordPress - Virtual Host Plugin. 2005-04-23 09:25:33

    [...] ess the /wp-admin/ directory on the main blog, they will be redirected to their vhost. Read more over at skippy.net and get the plugin! &rasquo; Awesome. [...]

  7. 551 Hugos House of Weblog Horror » Blog Archive » virtuelle Hosts mit WordPress 2005-04-23 10:41:09

    [...] open sources JBuilder virtuelle Hosts mit WordPress Das Vhost Plugin ist mein momentaner Favorit der Beiträge zum Plugin-Wettbewerb für WordPress. [...]

  8. 550 skippy 2005-04-23 11:17:17

    Vix: I'm using PHP 4.3.10 and MySQL 4.0.24. I don't think you're MySQL 4.0.22 version should be the problem.

    Line 136 is: $site = parse_url(strtolower($user_url));, which check's the user's URL as defined in their profile. From the error message you supplied, it looks like the user's URL is not a fully-qualified domain name. Can you double check that please?

  9. 563 Vix 2005-04-25 00:02:34

    Yes it wasn't a fully qualified domain because it was set to the default which is http://

    After putting in an url is was okay.

    I'll try again with a different install of wordpress and see if I get the same errors.

  10. 564 dotcomUNDERGROUND 2005-04-25 10:45:02

    great plugin

    thanks

  11. 565 dotcomUNDERGROUND Blogs 2005-04-25 10:47:55

    Wordpress vhost plugin

    found a gret werdpress plugin

    The vhost plugin binds a WordPress category to a virtual host on your webserver, either a sub-domain or a seperate fully-qualified domain. You can have as many such bindings as you have vhosts: just make a new category ...

  12. 1174 Weblog Tools Collection » Wordpress Plugin Competition Winners 2005-07-23 19:42:48

    [...] Overall Winner of the Plugin Competition is Skippy for authoring Vhosts and Secure Login. He wins a brand spankin’ new Sony PSP from WeblogToolsCollection.com (or $270, whichever he chooses). [...]

  13. 1165 Wordpress Plugin Competition Blog » Wordpress Plugin Competition Winners 2005-07-23 19:45:06

    [...] Overall Winner of the Plugin Competition is Skippy for authoring Vhosts and Secure Login. He wins a brand spankin’ new Sony PSP from WeblogToolsCollection.com (or $270, whichever he chooses). [...]

  14. 1187 Mangas Verdes » Vhost gana la competici 2005-07-24 03:01:26

    [...] Vhost, un hack que te permite crear una direcci

  15. 1170 Diario a Borbo » Ganadores Wordpress Plugin Competition 2005-07-25 08:56:05

    [...] El Ganador de la WordPress Plugin Competition es Skippy creador de Vhosts y Secure Login. [...]

  16. 1200 Denken Über » Ganadores del Wordpress Plugin Competition 2005-07-25 16:14:02

    [...] Gran Premio a Skippy por Vhosts y Secure Login. [...]

  17. 1208 La brujula verde » Vhost, plugin para WordPress 2005-07-26 07:19:19

    [...] Vhost es el plugin que ha ganado la competición creada por Weblog Tools Collection. Lo que hace es crear direcciones virtuales para aquellas páginas o categorías de WordPress que se desee. O, en otras palabras, vhosts virtuales que pueden ser un subdominio o un dominio cualificado (esto es, registrado y activo en tu servidor). Se pueden crear tantos hosts virtuales como quieras, y cada uno puede tener su propio diseño o template. Incluso se puede establecer, mediante la edición de los perfiles, que un usuario sólo pueda escribir posts para determinados vhosts o categorías. El funcionamiento del plugin puede verse en tangential.info. Este hack viene a completar un poco más la estupenda utilidad que es WordPress (esperemos que se incluya "de serie" en la versión 1.6). Servirá sobre todo a los blogs y bitácoras grupales, y nos facilitará la vida a muchos otros que contamos con colaboradores ocasionales, ya que podremos dar acceso a usuarios sólo a determinadas áreas y categorías de la interfaz de administración. Por: Guillermo - 10:19 —Enviar - Tema: wordpress, Universo blog añadir este post a del.icio.us No hay comentarios . Deja el tuyo [...]

  18. 1273 Tom 2005-08-04 18:48:18

    hmm this seems to be a very simple way of doing what I want wordpress to do. Hope it all works out ok.

  19. 1289 Plodz1 2005-08-06 12:52:47

    Warning: parse_url(http://): Unable to parse url in /home/public_html/wp-content/plugins/vhost.php on line 136

  20. 1413 aeos 2005-08-23 21:01:22

    I believe I must be completely dense, in not being able to figure this out. I have it installed, I have the subdomains setup (one server has them pointing to the root, one has them pointing to special folders /sub) but neither seem to use the custom themes. I have the categories setup right.

  21. 1414 skippy 2005-08-23 23:33:54

    aeos: all the domains should point to the same document root. In order for this plugin to grab the domains, they all need to point to the same WordPress installation.

  22. 1418 aeos 2005-08-24 14:48:58

    hm ok, maybe I missed a simple step. I activated the plugin. made a category called sub.domain.com that matched my subdomain, and I have the subdomain pointed to the root (index file) but the template does not change. My admin URL is www.domain.com (for the parse_url error fix)

  23. 1484 Josh 2005-09-05 16:58:58

    Very great plugin!!

  24. 1811 anonymous surfing 2005-11-12 21:41:17

    um - tangential.info seems to be displaying something else - looking at the whois records in october 2005 I believe the domain changed ownership & now serving a domainsponser.com esque page...

  25. 1802 skippy 2005-11-13 03:37:17

    Alas, yes, tangential.info was a free domain I picked up, and did not renew when the registration expired. If anyone wants to see a vhost installation in action, let me know and I'll revive it elsewhere.

  26. 2031 eas 2005-11-29 22:51:46

    Sorry about this! I can't get the HTML right to keep it from hiding half the error. Please delete the earlier ones:

    This plugin looks like it could be just the thing I'm looking for. Thanks for writing it!

    Now if I could only get it working!

    I can access the main index page of my site just fine, but if I go to foo.com, I get this error:

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 1=1 AND post_date_gmt <= '2005-11-29 22:25:59' AND (post_]
    SELECT DISTINCT * FROM wp_posts INNER JOIN wp_post2cat ON wp_posts.ID=wp_post2cat.post_id AND category_id= WHERE 1=1 AND post_date_gmt <= '2005-11-29 22:25:59' AND (post_status = "publish") GROUP BY wp_posts.ID ORDER BY post_date DESC LIMIT 0, 10

    I've created a toplevel category for foo.com, I've tried both copying and symlinking a theme at themes/foo.com. I've tried creating a post and assigning it to the foo.com category. I keep getting the message above.

    I've haven't done any template customization yet.
    PHP version 4.3.11
    MySQL version 4.0.25-standard
    Just downloaded wordpress today.

    Any suggestions would be very much appreciated!

  27. 2029 eas 2005-11-30 06:39:11

    Sweet! I figured it out. I figured that since apache was passing all requests for a given IP to a specific document root that I would have to define a server alias. Looks like I was wrong. Rather than change the apache config, which is a pain, I changed the plugin to use:
    $vhost = $_SERVER['HTTP_HOST'];
    instead of
    $vhost = $_SERVER['SERVER_NAME'];

    It seems to be working.

    Now to update the templates!

    Thanks again for writing this!

  28. 2062 Jonathan 2005-12-04 08:48:42

    Hey Skipy, when do you think this plugin will be updated for 1.5 and hopefully 2.x?

  29. 2063 skippy 2005-12-04 14:10:31

    Jonathon: vhost was developed for WordPress 1.5, and is compatible with all current 1.5 versions. I hope one site using this on a WordPress 1.5.2 installation.

    In order to make this compatible with WordPress 2.0, I'll need to make some pretty substantial changes. I haven't yet looked into it, so please don't hold your breath. If a true multi-blog solution is something you need in a hurry, check out WordPress MU.

  30. 2069 Jonathan 2005-12-05 01:07:08

    Thanks Skippy. I'm not looking for a true Multiblog though because I'm only looking at having static pages as subdomains (for static information primarily). I'm looking into MU for other needs though, which may arrise.

    I look forward to when you update a lot of your plugins so they are comp. with 2.0. Lots of good changes happening, just hope everyone can stay up with the times. I myself will need to upgrade quite a few of my designs and layouts because they are so code specific, but I'll hopefully find the time sometime soon.

  31. 2071 WordPress+GoDaddy: $50/year blogging at Applied Identity: yihaobenpu.com 2005-12-05 03:46:58

    [...] Now all I need to figure out is: How can I set up the vhost plugin? [...]

  32. 2150 remi 2005-12-14 21:07:29

    hat the hack am I doing wrong...

    my etc/hosts file (windows) is;

    127.0.0.1 remidian.nl
    127.0.0.1 tekstack.remidian.nl

    my apache config file is;

    DocumentRoot "C:/Apache/Apache/htdocs/wordpress-1.5.2"
    # ServerName remidian
    ServerName remidian.nl
    ServerAlias tekstack.remidian.nl
    ServerAlias oracle.tekstack.remidian.nl
    ServerAlias grid-10g.oracle.tekstack.remidian.nl
    ServerAlias rdbms10g.oracle.tekstack.remidian.nl
    ServerAlias unix.tekstack.remidian.nl

    I've set up two categories;
    remidian.nl and tekstack.remidian.nl

    But when I go to tekstack.remidian.nl I get zero results, a blank page....

    I have verified that the "if ($site['host'] != $vhost) {" comparison goes to true but than nothing happens...

    Did I overloook someting??

    Anyway thanks in advanse!

    Regards Remi

  33. 2151 skippy 2005-12-14 21:11:25

    A blank page usually indicates a PHP error. Have you looked in the Apache error log?

  34. 2159 remi 2005-12-15 14:01:57

    Yep, it was blanc...

    I forgot to mention that I did NOT make the directories in wp-content/themes/ for the tekstack.remidian.com category, I believe that was not mandatory?

    Is there any other way I can debug ...

    Thanks

    Remi

  35. 2157 skippy 2005-12-15 14:33:16

    remi: when you say "it was blank", are you referring to the page, or to the Apache error log? If you received a blank page, there should be an entry in the Apache error log.

    Try making the wp-content/themes/tekstack.remidian.com directory -- just copy the default theme into there, to make sure that it works.

  36. 2160 remi 2005-12-15 16:00:06

    Thanks a lot Skipyy

    I'll do that first thin I get home;

    http://anwb.nl/verkeer/popup_regioverkeerssituatie_amsterdam.nl.html

    'file' is dutch for 'traffic jam' ;)

    I work in Amsterdam ...

    Regards

  37. 2164 remi 2005-12-15 18:34:16

    Hi back again, Hussled through the traffic jams ...

    Allrighty then I did as you told me (only through a soft link (ln -s))

    Now I got the error below;

    WordPress database error: [Not unique table/alias: 'wp_post2cat']

    SELECT DISTINCT * FROM wp_posts LEFT JOIN wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) LEFT JOIN wp_categories ON (wp_post2cat.category_id = wp_categories.cat_ID) INNER JOIN wp_post2cat ON wp_posts.ID=wp_post2cat.post_id AND category_id=10 WHERE 1=1 AND (category_nicename = 'live-blog') AND post_date_gmt

  38. 2165 skippy 2005-12-15 18:45:53

    Are you using any other plugins? vhost shouldn't be producing quite that query, I don't think (though it's been awhile since I've looked at it).

  39. 2166 remi 2005-12-15 18:46:19

    Sorry Skippy

    That query error cam because of the following;

    I had the following statement in my templates index.php;

    query_posts('category_name=Live Blog')

    So that query error is gone now, however I'm still not there since tekstack.remidian.com is showing exactly the same as remidian.com ...

    What am I nod woing wrong ...

    Thanks again!

  40. 2167 remi 2005-12-15 19:06:13

    Allrighty the, sorry for bothering youy again.

    I made one assumption ...

    I thought I could map the default category to, ie the url without any subdomain (remidian.com), to a category I named 'remidian.com' ...

    It is working now ... Assumption is the mother of all ...

    Is it true that i can not achieve that...

    I tried to comment the following;

    //if ($site['host'] != $vhost) {
    But I see that when the url is remidian.com, the vhosts function is not invoked at all...

    Remi

  41. 2168 remi 2005-12-15 19:18:16

    Again too fast in bothering you;

    vhost.php was invoked but I was logged in as admin;

    if ('10' == $user_level) {
    // we don't want to lock out the admin
    return;
    }

    I got it working now ...

    Thank you VERY much for your time! If you ever stumble over an Oracle (you know that not so open source database) issue don't hesitate to call ;)

    Thanks again and have a very nice day!

  42. 2193 remi 2005-12-20 19:44:08

    Hi Skippy

    I have rewritten you vhost_join function to enable child categories;

    function vhost_join($join = '') { global $wpdb, $vhost_cat; if (false === stristr($join, " INNER JOIN $wpdb->post2cat ON ")) { //$join .= " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID=$wpdb->post2cat.post_id AND category_id=$vhost_cat "; /* REVHACK, 12/20/2005 8:40PMm (support child categories */ $_children = ltrim( get_category_children($vhost_cat,','), ','); if ( $_children == ''){ $join .= " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID=$wpdb->post2cat.post_id AND category_id=$vhost_cat "; }else{ $join .= " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID=$wpdb->post2cat.post_id AND (category_id=$vhost_cat OR category_id in ($_children))"; } } return $join; } // vhost_join

    I'm not really into wordpress and it might be a very dirty solution, but it looks like it works...

    remi@

  43. 2211 // remidian.com // blog archive // vhost // 2005-12-21 15:37:41

    [...] I use ‘Skippys’ vhost plugin. [...]

  44. 2219 Kaufman’s Lab » Plugins to get later 2005-12-23 00:25:49

    [...] WP-Scrobbler is a plugin for Wordpress 1.5 that displays your AudioScrobbler recently played songs in your desired location on your Wordpress blog. http://www.skippy.net/blog/2005/04/20/plugin-vhost/ Plugin: Vhost 17 [...]

  45. 2496 Peter McCarroll 2006-01-22 10:36:52

    Has anyone tried this in WordPress 2.0 (I can't see anything in 2.0 that does this).

    Thanks

  46. 2558 skippy 2006-01-23 00:21:44

    Peter: I've not tried this with WordPress 2.0 yet, and I likely won't have the time to do so any time soon. If you test it, do please let me know!

  47. 2864 dwang99 2006-02-21 01:18:33

    Hi Skippy,

    Thanks for a great plugin.

    I'm testing it on a Debian-base box, with apache2, php4. i have a stock wordpress 2.0.1 without any other plugins or anything else.

    I have it working except for the situation where a user tries to login into the 'wrong' site. For example if user1 is setup for user1.test.com but logs into user2.test.com, i see that you have a redirect to send them to their appropriate user1.test.com/wp-admin address.

    However, I receive a "Warning: Cannot modify header information - headers already sent by (output started at /var/www/wordpress/wp-admin/admin-header.php:15) in /var/www/wordpress/wp-content/plugins/vhost.php on line 174". [the 174 line number may be wrong since i was adding echo commands to figure out what was going on in the code].

    From what I can see, this is probably correct, since the add_action used in vhost is hooked to admin_head for the redirect. I am assuming the above error is generated because of the html header information added by admin_head before the header(location:...) of vhost's redirect occurs and this error comes up.

    Have you seen this issue? Is there a different hook? Do I have something set up wrong?

    Thanks for any help or insight.

  48. 2939 Mark 2006-03-05 21:05:32

    Skippy, this looks like a great plugin - if only it would work on WordPress 2.0.1!

    I've also installed it for a WP 2.0.1 blog, and while the category filters seem to work in so far as they filter out the posts correctly, there are a few remaining problems:

    1) Themes don't work
    2) The wp-admin stuff doesn't seem to work
    3) The category names don't update correctly when using the description field + newline markup.

    Anyway, this plugin has great potential and thanks for your work so far skippy!

    Hopefully you will find the time to re-write it to work with WP 2.x :-)

  49. 2937 skippy 2006-03-05 21:11:47

    Mark, vhost 1.5 works with WordPress 2+.

  50. 2938 Mark 2006-03-05 21:35:57

    Doh - sorry! Just discovered that...

    Am having problems at the moment (blank screen), but will investigate further.

  51. 2950 Yukko 2006-03-07 17:56:17

    Should I activate PHP on all subdomains or only the main one?

  52. 3261 Franky 2006-04-24 19:38:14

    Hi, Skippy,

    I really like this one, installed at my wordpress 2.0.2 and works fine. One question: could my default wordpress blog still display all users posts? right now it seems they are all independent for the posts.

    thanks,Franky

  53. 3211 kuslahne 2006-05-09 05:28:00

    Wow, awesome plugin..

  54. 3032 Aventuras de un Webmaster 2006-06-15 10:07:22

    Thanks for a great plugin!!!!!!!

  55. 3145 John Praca 2006-06-19 08:13:30

    hi there!

    Yes it's good, really good plugin very useful, i m trying sth similiar in my mu version

  56. 3289 Jonathan 2006-06-30 13:26:37

    Whoa! This is exactly what I've been looking for. I didn't even think to search for a plugin. Thank you for releasing this!

  57. 3286 Continuous Learning » Hopefully, 3rd try is a charm… 2006-12-05 06:14:51

    [...] So far, I definitely am impressed.  The install is straight forward (especially combined with a host such as DreamHost that offer one-click install), and there are numerous themes and plugins available.  I have yet to explore much, but below are some of my initial needs. Does WORDPRESS provide virtual domain mappings? The answer seem to Yes, based on http://www.skippy.net/blog/2005/04/20/plugin-vhost/.  However, I have not yet determined whether this work as advertised [...]

  58. 3890 Mike 2007-02-21 03:20:45

    Hi

    Thanks, this looks like a good idea but having trouble with it.

    I upload the vhosts.php to plug in directory and activate it and get

    Warning: Cannot modify header information - headers already sent by (output started at /home/fastsite/public_html/wp-admin/admin-header.php:16) in /home/fastsite/public_html/wp-content/plugins/vhost.php on line 174

    Is there something to change, not much of a guru and couldnt see any options to check configuration before enabling it.

    Thanks

    Mike

  59. 3893 skippy 2007-02-21 13:35:44

    Mike: I am no longer providing support for my WordPress plugins. You'll need to seek help at the WordPress support forum, or try your luck with the WP Pro mailing list.

Leave a Reply



About

Brewer philosopher.

User