I have a wp instalation on example.com and want to have secondary.com to show contents of example.com/b (b is a page) but keep secondary.com in the url (not secondary.com/b)

I tried this approach: https://stackoverflow.com/a/35272993/2095642

I have both domains pointed to one directory, I use this in my wp-config.php:

//this works, enables both domains to show the same wp installation
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);

and this in my .htaccess:

#this works, changes example.com/b url to secondary.com
RewriteCond %{HTTP_HOST} example.com$
RewriteRule ^b/(.*)$ https://www.secondary.com/$1 [L,QSA,R=302]

#this doesn't take effect and shows homepage on secondary.com
#I want it to keep only secondary.com in URL but show page /b/.
RewriteCond %{HTTP_HOST} secondary.com/?$
RewriteRule ^$ /b/ [L,QSA]

The second rule works as it should when pointed to a non-wp directory - retains url but shows directory's index. But when pointed to a wp page path, it doesn't.


  • 2
    "RewriteRule ^$ /b/ [L,QSA]" - The problem here is the way WP routes URLs. Whilst you internally rewrite the request to /b/ (or should that be /b?) - WordPress itself still sees the initial URL that was requested (the value of $_SERVER['REQUEST_URI'] PHP superglobal). This will need some PHP coding. OR you can take a different route and configure a reverse proxy, but this potentially requires access to your server config.
    – MrWhite
    Commented Oct 21, 2019 at 10:32

1 Answer 1


There is a plugin that does exactly this:


Anyway, it would be nicer to have things under control with an understandable few lines of script, so I'm still open to answers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.