How can I do a mod_rewrite on a multisite network to change the document_root?

I have been spending most of a day searching the internet for an answer. I have multisite working and two subdomains working. I also want to run an integrated script called The Next Generation of Genealogy Site Building. The issue is that for this script to function properly it should be remotely located at the mapped domain. The problem I'm having is that I can't get the network-activated integration plugin (tng-wordpress-plugin) to locate the correct tng install (the path is always the network host path).

Is there ANY way to set on a per mapped domain basis the correct path to the tng installation? This path would be (base path of mapped domain/public_html/tng/.

Thanks!

  • Barry

    I'm not sure I'm following your description -

    The issue is that for this script to function properly it should be remotely located at the mapped domain

    I assume you mean the main script not the "tng-wordpress-plugin".

    If you have an integration plugin, do the instructions for that mention where the main script should be? Is it expecting it to be on it's own domain somewhere else - i'd assume if it's a wordpress integration plugin, then it would integrate somehow :slight_smile:

    Is there ANY way to set on a per mapped domain basis the correct path to the tng installation? This path would be (base path of mapped domain/public_html/tng/

    Not sure how you would identify it? You won't be able to do anything with domain mapping, as that needs a wordpress site to be running at the location in order for it to change things around - if you are running the tng script then the domain mapping plugin won't actually be running.

    This (if you ignore the bluehost parts - unless you are on bluehost), shows how to use mod_rewrite to run a script from a directory as if it is in the root of the domain, but as I don't know anything about the script / system you are running I can't be more specific.

    https://my.bluehost.com/cgi/help/347

  • HeatherFeuer

    I am not on Bluehost and I am a Reseller with the ability to edit DNS Zones for sites I host -- which are all I am working with at the moment. Right now the structure is:
    uniquelyyourshosting.com (multisite host, primary domain, and web host)
    -- site1.uniquelyyourshosting.com (mapped to site1.net)
    -- site2.uniquelyyourshosting.com (mapped to site2.com)

    All three sites have WordPress installed. uniquelyyourshosting.com has WP installed at the root and handles all the plugins. site1 and site2 have the following directory structure:
    DOCUMENT_ROOT
    --.htaccess
    -- index.php
    -- wp (folder)
    -- tng (folder)

    This won't be a gigantic multisite network and rather specialized. From what I have discovered so far, I have begin to realize that any solution is going to involve some hard coding on my part.

    What I was rather hoping was that the domain_mapping table could have an extra row to set a remote document root so that when plugins like the integration one ask for the absolute path to an install that is remotely located it will use the mapped document root to start from.

    I hope that clears up some confusion.

  • Barry

    I hope that clears up some confusion.

    Actually, it confuses things more :slight_smile:

    So tng is run from the tng directory, and isn't a wordpress plugin (so domain mapping won't be running when that is), and you have a WP site in wp - do you also want that to function at the root of the site?

    I'm afraid it's looking like you won't be able to use rewrites to solve this issue - you may have to get into the code of your integration plugin and directly edit that.

  • HeatherFeuer

    I'm sorry Barry!! In order for tng to be integrated with wordpress is for each app to be in its own folder under root.

    There IS a plugin. It's called tng-wordpress-plugin. The original version of the plugin is located in the WordPress Plugin Repository. An updated version of the actual plugin file tng.php is available on the tng website (lythgoes.net/genealogy/software.php. When the plugin installs, it needs to find the tng install -- usually in /public_html/tng/. However, because the plugin is installed from the network, it doesn't find the respective mapped domain's tng folder -- it's looking for it in home/cheather/public_html/tng rather than home/site1/public_html/tng/, which is the mapped domain's path to tng. The plugin won't work, thus integration won't work, because it can't find the correct path to tng.

    Each installation of tng includes specialized folders to contain pictures, documents, census images, etc. so they need to be stored on individual domains. Otherwise, my primary domain would become overwhelmed!

    If it would help you, I would be happy to email you my login creds so you can see from the dashboard...

  • Barry

    Can you let me know if I'm reading this correctly, I'm very confused at the moment :slight_smile: ?

    All three sites have WordPress installed. uniquelyyourshosting.com has WP installed at the root and handles all the plugins. site1 and site2 have the following directory structure:
    DOCUMENT_ROOT
    --.htaccess
    -- index.php
    -- wp (folder)
    -- tng (folder)

    You have a main site running WP that has the plugin activated, and then you have two other sites with different WP installs?

    I'm trying to work out what you are trying to do :slight_smile: You want tng to run on the two other sites, with their own WP installs - but you are activating the tng integration plugin on the main site? Not the two sites that you want to integrate?

    Are you using the domain mapping plugin to map to the two other wordpress installs (not sure how you are doing that if you are)

  • HeatherFeuer

    Can you let me know if I'm reading this correctly, I'm very confused at the moment :slight_smile: ?

    Yes, you are.

    You want tng to run on the two other sites, with their own WP installs - but you are activating the tng integration plugin on the main site? Not the two sites that you want to integrate?

    Ideally, I would want the two other sites to use the network version of WordPress and tng to run remotely on site1 and site2 mapped domain. It just so happens that they already had wordpress installed. But you helped me clarify what I'm trying to do.

    IDEALLY, this is the structure I would want:
    uniquelyyourshosting.com (multisite host, primary domain, and web host)
    -- site1.uniquelyyourshosting.com (mapped to site1.net)
    -- site2.uniquelyyourshosting.com (mapped to site2.com)

    The PATH structure would be as follows:
    Network Host DOCUMENT_ROOT
    [wordpress installed in root]

    Site1 DOCUMENT_ROOT
    -- tng (folder)
    Site2 DOCUMENT_ROOT
    -- tng (folder)

    WordPress and the TNG plugin would be located on the Network Host, and would need to find the path to the tng folder on each individual mapped domain. But I just had a thought. With this structure and WordPress not needed on the mapped domain, maybe I could just put the tng install in the root. I am going to try that right now but I suspect that the plugin still won't recognize the remote install.

    So IDEALLY the structure would be:
    NETWORK HOST
    --WordPress with plugins
    MAPPED DOMAINS
    --TNG installed in the root

    I am currently using the subdomain mapped to top-level domain structure of Domain Mapping. I guess what I was hoping for was to be able to include in the domain mapping an extra setting for path/to/tng/.

  • HeatherFeuer

    You are right. It didn't. But that would be the best structure to start from -- meaning wordpress on the host site and tng on the mapped domains. Since this is a unique structure, I'd rather keep the hacking of the plugin file to a minimum. I can do that best by having a single include statement at the beginning of the file and keep the path statements in a separate file.

    My problem now is that I haven't been able to figure out the correct way to achieve what I want. As usual, my knowledge of mod_rewrite (in .htaccess) and php is just enough for me to break things! :slight_frown: That's the main reason for asking my question: How do I define the path to the remote (mapped domain) document root so the plugin can find each tng install? Then I would only have to edit one file to set the path.

  • HeatherFeuer

    Okay... Here is the relevant code in the tng.php plugin file.

    //Searches server for TNG files
    function mbtng_search_for_tng ($path = '', $go_back = true) {
    	global $countit;
    	if ($path == '..')
    		$oldpath = basename(getcwd());
    	else
    		$oldpath = '';
    	if ($path != '')
    		if (!@chdir($path)) {
    			header('Location: '.get_bloginfo('wpurl').'/wp-admin/admin.php?page=tng-wordpress-plugin/tng.php&updated=notfound');
    			die();
    		}
    	$path=getcwd();
    	$dir = @opendir($path);
        if ($dir) {
    		$element=readdir($dir);
            while ($element !== false) {
                if (is_dir(mbtng_folder_trailingslashit($path).$element) && $element != "." && $element != ".." && $element != $oldpath) {
                    mbtng_search_for_tng(mbtng_folder_trailingslashit($path).$element, FALSE);
    				chdir($path);
    			}
                elseif ($element != "." && $element != "..") {
    				if ($element == 'ahnentafel.php' && mbtng_correct_path($path)) {
    					update_option('mbtng_path', mbtng_folder_trailingslashit($path));
    					header('Location: '.get_bloginfo('wpurl').'/wp-admin/admin.php?page=tng-wordpress-plugin/tng.php&updated=search');
    					die();
    				}
    			}
    		$element=readdir($dir);
            }
            closedir($dir);
        }
    	if ($go_back)
    		mbtng_search_for_tng('..', TRUE);
        return;
    }
  • Arnold

    I'm coming late to this but If I understand correctly your talking about paths as in file paths rather than urls. You have a Multisite main at your
    /public_html/
    and you would like it to look like there are two other domains at
    /public_html/site1.net/tng
    and at
    /public_html/site2.com/tng
    so you can put your site specific TNG files in each. You can't have them above /public_html/ as you previously indicated as there would be no url to any files there. You could have php read files above /public_html/ but they are not part of the web files.

    Then if you are a subdomain Multisite install you can just pick up your subdomain as the base for constructing your url to the site specific files.

    Domain mapping would be on top of this, but that just hides your subdomain. You can use get_blog_details()

    http://codex.wordpress.org/WPMU_Functions/get_blog_details

    To get the underlying subdomain information.

    Haven't tried this but I think it can work with some mods to the integration plugin.

  • HeatherFeuer

    @Arnold

    and you would like it to look like there are two other domains at
    /public_html/site1.net/tng
    and at
    /public_html/site2.com/tng
    so you can put your site specific TNG files in each. You can't have them above /public_html/ as you previously indicated as there would be no url to any files there. You could have php read files above /public_html/ but they are not part of the web files.

    Not quite. The mapped domains would be actual domains located on the same webserver as the host domain but with their own structure...

    So let's same there is site1.uniquelyyourshosting.com that is mapped to site1.com. site1.com is a remotely located (on the same server) site with it's own path/to/public_html/. In THAT public_html directory is where tng is installed.

    I want to tell the tng plugin to find the REMOTE site1/path/to/public_html. I think if I can figure out how to get tng to find the public_html folder located in the remote directory, the plugin will function correctly. I currently do NOT have the plugin network-activated. As Network Admin, I would need to individually activate the plugin on each mapped domain individually.

    I've been looking at how to use $_SERVER, basename() and dirname() as possible ways to point to the remote location but can't seem to quite get it... What would be TOTALLY awesome would be another field in the domain_mapping table for path/to/tng that would be recognized by the plugin. The plugin then adds options to the wp_[blogid]_options table for mbtng_path and mbtng_url and it's the mbtng_path that needs to point to the remote directory.

    I'm making my head hurt, which means I'm learning! Which isn't bad for an old broad like me...

  • Arnold

    So the site1 and site2 are NOT part of the Multisite? They are in there own domain structures.

    Main /home/uniquelyyourshosting.com/public_html/
    site1 /home/site1.net/public_html
    site2 /home/site2.com/public_html

    If that's they case the only way you could do it is hard code the paths. Depend on knowledge outside theprimary domain which only you can give it. No way it would know to look above /public_html/ unless you tell it specifics.

  • HeatherFeuer

    Mutisite Network:
    Host: uniquelyyourshosting.com
    Site1: wptngdemo.uniquelyyourshosting.com
    wptngdemo.uniquelyyourshosting.com has domain mapping set to:
    -- uniquelyyourshosting.net

    uniquelyyourshosting.net is a domain hosted as a client on the reseller account of uniquelyyourshosting.com (which is also the multisite host).
    uniquelyyourshosting.net has a public_html folder of its own in which is stored all the files for the webapp tng (The Next Generation of Genealogy Site Building)
    The domain uniquelyyourshosting.net has a DNS A record pointing to the dedicated IP for uniquelyyourshosting.com (which is NOT the shared server IP)

    The plugin file, tng.php, that integrates WordPress with TNG resides in the plugins folder for the multisite WordPress installation on uniquelyyourshosting.com. The plugin needs to know the absolute path to the tng installation (which resides in the public_html directory of the mapped domain -- uniquelyyourshosting.net).

    I am trying to figure out how I can tell tng.php to look for the tng installation located in the public_html folder at uniquelyyourshosting.net. I have explored the possibility of using mod_rewrite in the .htaccess file in the root of uniquelyyourshosting.com. I have also explored the possibility of creating a php script to tell tng.php what the correct path should be which could be included in the tng.php file. So far nothing I have tried is working and I'm confusing myself in the process.

    I do realize that I am asking for something rather complicated that may not be possible. I'm just hoping that it CAN be possible...

  • Arnold

    You may be misunderstanding what Domain Mapping does.

    Multisite can be set as either subdomain or subdirectory install. If it's a subdomain install then you must have a wildcard subdomain setup for your primary domain.

    *.uniquelyyourshosting.com A whatever IP the primary is

    All this does I makes sure that ANY subdomain of uniquelyyourshosting.com will be sent to the Same IP address. WordPress Multisite then figures out from the subdomain name which set of database tables in Multisite to use.

    You said

    Site1: wptngdemo.uniquelyyourshosting.com
    wptngdemo.uniquelyyourshosting.com has domain mapping set to:
    -- uniquelyyourshosting.net

    uniquelyyourshosting.net is a domain hosted as a client on the reseller account of uniquelyyourshosting.com (which is also the multisite host).

    If that is so it will be directed to the Multisite site and translated to one of the blogs on Multisite. If you then Domain Map on top of that with uniquelyyourshosting.net Domain mapping will be translated to wptngdemo.uniquelyyourshosting.com and you still end up on Multisite in the same blog. All Domain mapping does is translate from a domain name to a multisite site. It cannot go to another IP address or to another installation of WP.

    If you set the IP of uniquelyyourshosting.net to something Other than the IP of uniquelyyourshosting.com then Domain mapping and Multisite never get a chance to run because it went somewhere else.

    From above you have the IP of .net set to the IP of .com so that will get you to Multisite but no amount of rewriting will take you to an entirely different directory as you indicate.

    uniquelyyourshosting.net has a public_html folder of its own in which is stored all the files for the webapp tng (The Next Generation of Genealogy Site Building)

    Everything that Multisite and Domain Mapping do can only occur below the Multisite root directory. That's the whole purpose of a public_html directory, It's isolation for that website so things can't go climbing out of it and looking at the rest of the server. You're trying to break this basic feature.

  • HeatherFeuer

    All is not completely lost. I think I am going to go ahead and install tng on the network host and see what I can do with file folders and such. Perhaps offer it as a "playground" to try out the integration and if they like it, I can upsell to a dedicated account. Meanwhile, I am toying with the idea of a webring and some other ideas.

    I do so appreciate the help and if I have sparked some interest in an alternative type of network, so much the better. The plugin for integrated logins across single sites isn't really viable for what I have in mind.

    Thanks again for the stellar efforts!!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.