• NOTE: This is for expienced users…. sorry noobies you’re on your own.

    How to map subdirectory blogs with Multi-stie Domain Mapping
    In order to be able to correctly configure your server you will need ACCESS TO HTTPD.CONF on your Apache server. This configuration CANNOT be done with .htaccess
    Main concept
    This is for website managers that have an established site and wish to create a blog network that extends further than their single domain where the url structure of the target domain needs to have a subdirectory.
    We achieve this by installing WP in a subdomain: blog-admin.mydomain.com and enable SUBDOMAIN networking.
    Then using a combination of server ENVIRONMENTAL VARIABLES, ALIAS and modification of the MS/MU files in WP.
    This requires PLANING, so work out exactly what you want before you start.

    WARNING: By modifying the httpd.conf (or site specific include as in PLESK) incorrectly file you can cause your web server to FAIL TO START. Furthermore you can cause your existing site to NOT FUNCTION CORRECTLY. That being said let’s have some fun.
    For example Purposes let’s set up our domain structure:
    Main site blog admin:
    https://blog-admin.mysite.com

    Blogs (or any combination):
    https://www.mysite1.com/en/blog/
    https://www.mysite1.com/es/blog/
    https://www.mysite1.com/fr/blog/
    https://www.mysite2.com/ blog/
    https://www.mysite3.com/blog/

    Testing Environment:
    Windows 7 64bit
    (Xampp custom installation)
    Apache 2.2
    Mysql 5.21
    Php 5.3
    Highly recommended that you add the following to monitor your rewrite:
    RewriteLog [AbsolutePathToLogFile]/rewrite_log_blog
    RewriteLogLevel 3

    The program mTail for windows is the same as tail in linux so you can monitor in real time all the rewrite steps.

    Considerations for Production Servers:
    Make sure that if you have php_open_basedir set you must include the ABSOLUTE PATH TO WP INSTALLATION DIRECTORY

    If you have SymLinksIfOwnerMatch enabled such as PLESK, you will need to override this for your WP installation directory unless you install all the files with the same user

    So, here we go!

    Step One: Create directory structure
    Create all the necessary folders. In this example case I’ve created:
    [AbsoluteSitePath]/mysites/
    [AbsoluteSitePath]/mysites/mysite1.com
    [AbsoluteSitePath]/mysites/mysite1.com/blog-admin
    [AbsoluteSitePath]/mysites/mysite2.com
    [AbsoluteSitePath]/mysites/mysite3.com

    Step Two: Setup Webserver
    Depending on what software you use you will need to make the necessary entries in your server configuration.
    For testing purposes I’ve edited the /winidows/system32/drivers/etc/hosts file with the following in order to get the local DNS to handle the request:
    127.0.0.1 blog-admin.mysite1.com
    127.0.0.1 https://www.mysite1.com
    127.0.0.1 mysite1.com
    127.0.0.1 https://www.mysite2.com
    127.0.0.1 mysite2.com
    127.0.0.1 https://www.mysite3.com
    127.0.0.1 mysite3.com

    Make the virtual hosts for each domain:
    <VirtualHost mysite1.com:80>
    ServerAlias https://www.mysite1.com
    ServerName mysite1.com
    …..
    </VirtualHost/

    In EACH VirtualHost entry you will need to add the following (This is for testing, on a production server you should restrict the AllowOverride to something more secure:
    <Directory “[AbsoluteSitePath]/mysites\mysite1.com\blog-admin”>
    Order deny,allow
    Deny from all
    Allow from all
    AllowOverride All
    </Directory>
    STEP 3: Install WordPress
    Copy the wordpress files to [AbsoluteSitePath]/mysites/mysite1.com/blog-admin.
    Install WP as per the instructions
    Enable Multsite in the wp-config.php with define(‘WP_ALLOW_MULTISITE’, true);
    Create the blogs.dir directory in wp-content.
    Now STOP! The next steps are different that the standard MS installation.
    Add the following the wp-config.php file replacing your WP domain instead of mine:
    define( ‘MULTISITE’, true );
    define( ‘SUBDOMAIN_INSTALL’, false );
    //$base = ‘/’;
    define( ‘DOMAIN_CURRENT_SITE’, ‘blog-admin.mysite1.com’ );
    define( ‘PATH_CURRENT_SITE’, ‘/’ );
    //define( ‘SITE_ID_CURRENT_SITE’, 1 );
    //define( ‘BLOG_ID_CURRENT_SITE’, 1 );
    Step 4: Create the blogs and install MU Domain mapping plugin
    Note: there is a bug with eliminating a blog and then creating another with the SAME PATH. This is IMPORTANT because the PATH is variable that this tutorial depends on
    I’ve now created the following blogs:
    ATTENTION: Look at the pattern of the mysite1.com blogs. The in language “code”. This is important for the rewrite as the base is “mysite1blog” + “[LanguageCode]”

    Address: mysite1blogen
    Title: My Site 1 Blog 1
    Address: mysite1bloges
    Title: My Site 1 Blog 2
    Address: mysite1blogfr
    Title: My Site 1 Blog 3
    Address: mysite2blog
    Title: My Site 2 Blog
    Address: mysite3blog
    Title: My Site 3 Blog 3
    Important: Uncheck “Update site url and home as well” next to the path field
    Now we must edit each one so that it has the correct SiteURL, PATH and HOME. For example we go to the sites-> edit page for mysite1blogen and put:
    Domain: blog-admin.mysite1.com
    PATH : /mysite1blogen/
    SiteURL: https://www.mysite1.com/en/blog/
    Home : https://www.mysite1.com/en/blog/
    FileUpload URL : https://blog-admin.mysite1.com/mysitebogen/files
    Domain: https://www.mysite2.com
    PATH : /mysite2blog/
    SiteURL: https://www.mysite2.com/blog/
    Home : https://www.mysite2.com/blog/
    FileUpload URL : https://www.mysite2.com/blog/files
    Now install the MU domain mapping plugin and follow its instructions.
    Add blog-admin.mysite1.com to the CNAME in the options page.
    Map ONLY mysite2blog to mysite2.com and mysite3blog to mysite3.com. DO NOT MAP mysite1.com to anything.
    STEP 5: Customizing the Rewrite Rules
    Create a file called rewrite.wp-multi.include and save it to the apache “conf” folder.
    Copy the following into it:
    RewriteEngine On
    RewriteRule ^index\.php$ – [L]
    RewriteRule ^(/[_0-9a-zA-Z-/]+/) index.php [L]
    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} –d
    RewriteRule ^ – [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

    RewriteCond %{ENV:BLOG_BASE} ^(.*)$
    RewriteRule . %1index.php [L]

    STEP 6: Installing and Configuring the Module Rewrite
    Inside EACH <Directory “D:\Home\htdocs\checkout\adminsystem\www\mysites\mysite1.com\blog-admin”> Add the follow : Include conf/rewrite.wp-multi.include
    Now, we must configure each VirtualHost .
    VirtualHost mysite1.com
    NOTE: As we are using a variable first “folder” in the blog url which in our case is the Language Code. If the patter is /blog/en/ for example we would not need to edit the httpd.conf file if we create more blogs.
    Add the following inside the VirtualHost directive( substitute [AbsolutePathToHtdocs] for your server configuration:

    For Pattern /“LanguageCode”/blog/:
    Alias /en/blog [AbsolutePathToHtdocs]/mysites/mysite1.com/blog-admin/
    Alias /es/blog [AbsolutePathToHtdocs]/mysites/mysite1.com/blog-admin/
    Alias /fr/blog [AbsolutePathToHtdocs]/mysites/mysite1.com/blog-admin/
    Now add:
    RewriteEngine On
    # RewriteLog [PathToYourLogFile]
    RewriteLogLevel 3
    RewriteRule .* – [E=BLOG_PATH_BASE:mysite1blog]
    RewriteCond %{ENV:BLOG_PATH_BASE} ^(.*)$
    RewriteRule ^/([a-z]{2})/(blog/)(.*) – [E=REDIRECT_SCRIPT_URL:/%1$1/$3,E=REDIRECT_BLOG_PATH:/%1$1/,E=BLOG_PREFIX:$1,E=BLOG_BASE:/$1/blog/]
    VirtualHost mysite2.com and VirtualHost mysite3.com
    Now add:
    RewriteEngine On
    # RewriteLog [PathToYourLogFile]
    RewriteLogLevel 3
    RewriteRule ^/(blog/)(.*)$ – [E=BLOG_BASE:/blog/]

    Alias /blog D:/home/htdocs/checkout/adminsystem/www/wp-blogs/blogadmin/
    STEP 7: Editing the WP PHP files
    ATTENTION: Make a backup of all files listed below!
    In this step we are going to modify the following files:
    sunrise.php
    ms-settings.php
    ms-load.php
    This can get a bit tricky.
    The main concept is now to use the Environmental Variable REDIRECT_BLOG_PATH to correctly find our blogs in the virtual system of WordPress

    Sunrise.php
    After Line 19 Add:
    // Detect if we are Redirecting our blog in a patterned sub-directory style
    $domain_mapping_id = ($_SERVER[‘REDIRECT_BLOG_PATH’]) ? false : $domain_mapping_id;
    Line 22 Replace with:
    // If we are re-mapping from domain.com/directory structure
    // $current_blog->path = ‘/’;
    $current_blog->path = ($_SERVER[‘REDIRECT_SCRIPT_URL’]) ? $_SERVER[‘REDIRECT_SCRIPT_URL’] : ‘/’;
    ms-load.php
    After line 140 add:
    // Check to see if we are coming from a pattern subdirectory structure
    $path = ($_SERVER[‘REDIRECT_BLOG_PATH’]) ? $_SERVER[‘REDIRECT_BLOG_PATH’] : path;
    After Line 163 Add:
    // Check to see if we are coming from a pattern subdirectory structure
    $path = ($_SERVER[‘REDIRECT_BLOG_PATH’]) ? $_SERVER[‘REDIRECT_BLOG_PATH’] : $path
    Ms-settings.php
    At line 50 Add:
    // Check to see if we are coming from a pattern subdirectory structure
    $path = ($_SERVER[‘REDIRECT_BLOG_PATH’]) ? $_SERVER[‘REDIRECT_BLOG_PATH’] : $path
    Replace Line 53 ($current_blog = get_blog_details ….) with:
    $current_blog = get_blog_details( array( ‘domain’ => $domain ,’path’=>($_SERVER[‘REDIRECT_BLOG_PATH’]) ? $_SERVER[‘REDIRECT_BLOG_PATH’] : false), false );
    After Line 74 ($path .= $blogname . ‘/’;) Add:
    $path =($_SERVER[‘REDIRECT_BLOG_PATH’]) ? $_SERVER[‘REDIRECT_BLOG_PATH’] : $path;
    $domain = ($_SERVER[‘REDIRECT_BLOG_PATH’]) ? $current_site->domain : $domain;

    Ms-default-constants.php

    At Line 30 Add:
    // For use in plugins that upload files or need to access uploaded files
    if(is_subdomain_install()):
    $domain = $current_blog->domain.””.(($_SERVER[‘BLOG_BASE’]) ? $_SERVER[‘BLOG_BASE’] : “”);
    else :
    $domain = $_SERVER[‘HTTP_HOST’].””.(($_SERVER[‘BLOG_BASE’]) ? $_SERVER[‘BLOG_BASE’] : “”);
    endif;

    define( ‘MS_CONTENT_URL’, “https://&#8221;.$domain.UPLOADS );

Viewing 12 replies - 1 through 12 (of 12 total)
  • Great post … but it’s very long and the forum formatting doesn’t help for readability. I’d recommend posting this as a tutorial on your own site (it will help drive traffic if nothing else) and/or submitting it as a Codex article.

    This is not something I would really recommend. If it works for you and your situation, great.

    Tho if you’re building actual physical folders and hacking core and the plguins, I think I’d rather go for multiple installs in one db with a shared userbase.

    Thread Starter BpPst

    (@bppst)

    This manual is for people that have established sites with their own e-commerce or content system that want to add wordpress blogs. Especially if you have many blogs like me (10 for one client with only 3 writers).

    It maintains everything virtual with one install of WP, one database and plugins can be shared across the network. Only 4 files relating to the multiple site files are touched updating shouldn’t be a problem.

    As a system architect my rule is avoid multiple deployments of anything.

    Once installed you can add a wordpress blog to any existing domain, with any existing structure, with any mapping you want. Freedom.

    This post is to solve the repeated question “How do I map to a domain.com/subdirectory”

    Otherwise the only solution is to use MovableType or live within the limits of WordPress… I don’t like limits nor do I like to be boxed into one solution.

    To MovableType or to WordPress, that is the question… that I had 5 days ago. Now I can do want I want and

    Thread Starter BpPst

    (@bppst)

    Estimated test install time: 2 hours
    If anyone finds it useful let me know ??

    This post is to solve the repeated question “How do I map to a domain.com/subdirectory”

    This only applies if the main domain is also hosted on the same server.

    Thread Starter BpPst

    (@bppst)

    True, if they are on different servers you have to install in the remote server WP, define the PATH correctly in the wp-config.php and then configure the MySql host to be the server where the WP database is installed (and logically configure the Mysql to accept the host)… most likely you would still have to do one or more of the steps above to make sure that the “PATH” and “Domain” are set correctly.

    I followed the steps, but I can’t redirect…

    I tried to do on the same domain (because wp is on blogs.domain1.com), and i want to access a special blog from domain1.com/blog/

    I applied the tutorial, but without the languagecode application…

    But the redirection fails as it tries to redirect as a loop… /blog/blog/blog/blog… and does not seem to reach the good path!

    Can someone help? (If you’re still here BpPST)

    Excuse my English, I’m French,
    Thanks,
    Corentone

    thanks for the info on this post. I think this is what i need to make my current situation work. I recently installed WP Multisite and have NOT yet been able to map the subdirectory sites to resolve at the same ip address. Do I need to make some configuration changes to the virtual host on my dedicated server?

    Please keep in mind while I read through your detailed explanation of what to do, about 1/3 the way down you lost me because of the lack of experience and technical knowledge I have around this subject matter. So take it easy on me!! ??

    Is there a way someone can help me to get my configurations correct? Is this something that has to be on my plesk cP?

    Please help!!!

    I’m not sure you need this thread. It’s for a very specific circumstance – where you want to map a domain *including* a folder with that domain.

    Not for making subdirectory sites in general.

    Thread Starter BpPst

    (@bppst)

    Hi Still Awake,

    I have this configuration up and running on our domains (all on the same server but different ip addresses):
    blogs.mydomain1.com
    https://www.mydomain1.com/en/blog/
    https://www.mydomain1.com/es/blog/
    https://www.mydomain1.com/fr/blog/

    https://www.mydomain2.es/blog/

    The configuration is tricking but works. You will have to have knowledge of mod_write and be able to edit the httpd (vhost for plesk) files.

    I have a dedicated server so I can do whatever changes I want. And I have many years experience.

    I’ve set it up on both windows locally and our production server.
    If you want to instant message me I can send you a Word document that I follow. Remember first to try on a local development server.
    Install, debug, take notes, fix, document and start again. Once you can run through and installation on your local server with no errores you can go to production.

    Note: This solution requires that the person using it have experience configuring webservers and good understanding of PHP. Anyone with a degree should be able to do it as it is a textbook case of Open Source modification to fit a specific need.

    Thread Starter BpPst

    (@bppst)

    @corentone – I have the option ” Permanent redirect (better for your blogger’s pagerank)” in “Domain Mapping Configuration” disabled.

    Check to see if that is the problem.

    @bppst – except people are finding this thread when trying to map just a regular domain to a blog in a subfolder install. Which is not what you did and not what they want.

    I’m just trying to make this crystal clear for anyone reading along and searching.

    If you have mainsite.com/subsite/

    and you want to domain map domain2.com to the subsite, this is NOT the post you want.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘How to Map a Domain with subdirectory to a Multi-site Network’ is closed to new replies.