Skip to main content

Host Multiple URLs in one WordPress account

Getting WordPress (WP) to serve multiple sites, with each site existing in it’s own subdirectory in OTDI’s Web Hosting, requires nested .htaccess files; One in the Document Root (/htdocs/) and one in each site’s top subdirectory.

So, for two subdirectories, you’ll need at least three .htaccess files. Additionally, you’ll need to add a chunk of code to the Document Root’s .htaccess file to fool WP into NOT auto-updating the file when a setting gets changed in the GUI. (Like when updating PermaLinks or Time Zone settings) This function is explained further at Perishable Press Stop WordPress from Changing.

Here’s what to put in the DocumentRoot .htaccess file, replacing the urlX & subdirectoryX tags with your own data:

##############################################################
# redirect urlA to subdirectoryA
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?urlA.org$
RewriteCond %{REQUEST_URI} !^/subdirectoryA/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdirectoryA/$1
RewriteCond %{HTTP_HOST} ^(www.)?urlA.org$
RewriteRule ^(/)?$ subdirectoryA/index.php [L]
</IfModule>

# redirect urlB to subdirectoryB
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?urlB.com$
RewriteCond %{REQUEST_URI} !^/subdirectoryB/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdirectoryB/$1
RewriteCond %{HTTP_HOST} ^(www.)?urlB.com$ RewriteRule ^(/)?$ subdirectoryB/index.php [L] </IfModule>

# To PREVENT WP from auto-updating this DocumentRoot's .htaccess file and
# breaking subdirectory site support, add these lines. Do Not Remove!

<IfModule mod_ignore_wordpress.c>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
</IfModule>

And here’s what to put in each site’s subdirectory .htaccess file, replacing the subdirectory tags with the name of the subdirectory they’re in:

##############################################
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirectory/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirectory/index.php [L]
</IfModule>
# END WordPress
#################################################