Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY000]: General error: 145 Table './skippy_skippy/h_sessions' is marked as crashed and should be repaired in system/classes/databaseconnection.php line 269
skippy dot net

Plugin: Vhost feed icon

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!


  • April 22nd, 2005
  • rob
    Wow, this looks very neat. I'll definitely have a play on my home server.
  • Vix
    I've been looking for something like this for ages! I'll let you know how it goes
  • Vix
    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
  • Vix
    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
  • April 23rd, 2005
  • April 23rd, 2005
  • skippy
    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?
  • Vix
    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.
  • dotcomUNDERGROUND
    great plugin thanks
  • April 25th, 2005
  • July 23rd, 2005
  • July 23rd, 2005
  • July 24th, 2005
  • July 25th, 2005
  • July 25th, 2005
  • July 26th, 2005
  • Tom
    hmm this seems to be a very simple way of doing what I want wordpress to do. Hope it all works out ok.
  • Plodz1
    Warning: parse_url(http://): Unable to parse url in /home/public_html/wp-content/plugins/vhost.php on line 136
  • aeos
    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.
  • skippy
    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.
  • aeos
    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)
  • Josh
    Very great plugin!!
  • anonymous surfing
    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...
  • skippy
    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.
  • eas
    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!
  • eas
    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!
  • Jonathan
    Hey Skipy, when do you think this plugin will be updated for 1.5 and hopefully 2.x?
  • skippy
    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.
  • Jonathan
    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.
  • December 5th, 2005
  • remi
    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
  • skippy
    A blank page usually indicates a PHP error. Have you looked in the Apache error log?
  • remi
    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
  • skippy
    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.
  • remi
    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
  • remi
    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
  • skippy
    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).
  • remi
    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!
  • remi
    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
  • remi
    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!
  • remi
    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@
  • December 21st, 2005
  • December 23rd, 2005
  • Peter McCarroll
    Has anyone tried this in WordPress 2.0 (I can't see anything in 2.0 that does this). Thanks
  • skippy
    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!
  • dwang99
    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.
  • Mark
    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 :-)
  • skippy
    Mark, vhost 1.5 works with WordPress 2+.
  • Mark
    Doh - sorry! Just discovered that... Am having problems at the moment (blank screen), but will investigate further.
  • Yukko
    Should I activate PHP on all subdomains or only the main one?
  • Franky
    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
  • kuslahne
    Wow, awesome plugin..
  • Aventuras de un Webmaster
    Thanks for a great plugin!!!!!!!
  • John Praca
    hi there! Yes it's good, really good plugin very useful, i m trying sth similiar in my mu version
  • Jonathan
    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!
  • December 5th, 2006
  • Mike
    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
  • skippy
    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.

About | Policies | skippy.net

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY000]: General error: 145 Table './skippy_skippy/h_sessions' is marked as crashed and should be repaired in system/classes/databaseconnection.php line 269
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY000]: General error: 145 Table './skippy_skippy/h_sessions' is marked as crashed and should be repaired in system/classes/databaseconnection.php line 269