I am using a single WordPress installation for two separate websites with different domains.

To redirect the second domain to its own index page I use.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^seconddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.seconddomain.com$
RewriteRule ^(.*)$ index.php?page_id=78 [NC,QSA]

this works great, but I don't know how to do this with specific pages, for example, the page for the imprint.

The first's page imprint has the permalink firstdomain.com/imprint and the second pages imprint has the permalink firstdomain.com/seconddomain-imprint.

How can I access this page with an URL like:

  • What do you mean by "imprint"? – MrWhite Jul 11 '18 at 17:12
RewriteCond %{HTTP_HOST} ^seconddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.seconddomain.com$
RewriteRule ^(.*)$ index.php?page_id=78 [NC,QSA]

The "problem" with this is that it rewrites seconddomain.com/<everything> to /index.php?page_id=78. If you only want the second domain's home page to be served with page_id=78 then you should change the RewriteRule pattern to match just the home page (ie. an empty URL-path). For example:

RewriteCond %{HTTP_HOST} ^(www\.)?seconddomain\.com
RewriteRule ^$ index.php?page_id=78 [QSA,L]

(I've also combined the two RewriteCond directives, escaped the dots and removed the trailing $ to catch a FQDN. The NC flag is also redundant here and the L flag is probably preferable to prevent further directives being processed unnecessarily.)

Then, for specific pages you would need to duplicate the above directives. For example:

RewriteCond %{HTTP_HOST} ^(www\.)?seconddomain\.com
RewriteRule ^specific-page$ index.php?page_id=NN [QSA,L]

Where NN is the appropriate page_id for /specific-page.

If you have many URLs then the directives can be altered to avoid having to include the RewriteCond directive every time.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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