We need to show a certain page on Wordpress using a different domain, so via .htaccess we do this:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain.org.uk$ [NC]
RewriteRule ^(.*)$ index.php?page_id=37440 [NC,QSA]
The page in question is password protected, but the standard password protection form will include the main site domain, and when clicking submit to login it in goes to a blank page.
So we customised the password protection form to submit to the new domain, e.g.
function my_password_form($form)
{
if(get_the_ID() == '37440' )
{
$form = '<form action="https://www.mydomain.org.uk/wp-login.php?action=postpass" class="post-password-form" method="post">
<p>This content is password protected. To view it please enter your password below:</p>
<p><label for="pwbox-37440">Password: <input name="post_password" id="pwbox-37440" type="password" size="20"></label> <input type="submit" name="Submit" value="Enter"></p>
</form>
';
}
return $form;
}
add_filter( 'the_password_form', 'my_password_form' );
Now the action is changed to the new domain, but when clicking Submit it goes to the following URL but it says its a 404:
https://www.mydomain.org.uk/wp-login.php?action=postpass
I also tried dynamically setting the site URL in wp-config.php depending on the domain uses (which I have successfully done in the past on another site which needed a second domain) but this also goes to a 404.
if($_SERVER['HTTP_HOST'] == 'www.mydomain.org.uk')
{
define('WP_HOME', 'https://www.mydomain.org.uk/');
define('WP_SITEURL', 'https://www.mydomain.org.uk/');
}
Does anyone know why, and how can we allow a login to the password protection page from this second domain?
Thanks