Assuming the /wp2
subdirectory containing the staging site has its own WordPress .htaccess
file (with the standard WordPress front-controller, see below). Then the .htaccess
in the document root should contain something like the the following, above any existing directives, to rewrite all requests to the wp2
subdomain to the /wp2
subdirectory:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(wp2)\.example\.com
RewriteRule (.*) /%1/$1 [L]
Then, the “standard” WordPress front-controller would be in the /wp2/.htaccess
file (this also prevents a potential rewrite loop):
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Note that I have removed the RewriteBase
directive entirely and removed the slash prefix on the last RewriteRule
substitution. This is so that it will load index.php
from /wp2/index.php
and not the document root. (Which is really how I would expect the main site in /wp1
to be configured.)