Hello
I tried to redirect my subdomain registration page on [multsite] to the main domain site registration page. I used the following code in my child theme functions.php for the site which I want to redirect its registration page:
//redirect to the registration page
function MyRedirect() {
if(is_page('register')) {
wp_redirect( 'http://domain.com/register/', 301 );
exit;
}
}
add_action('template_redirect','MyRedirect');
Interestingly, the above code did not work, .htaccess is not working as well. I am, for sure, missing something but I don’t know what! .htaccess code is:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
RewriteRule ^register/(.*)$ http://domain.com/register/$1 [R=301,L]
Any help from you is highly appreciated as I am really stuck in this.
Thanks in advance for all of you specially: @djpaul , @boonebgorges , @henrywright , @r-a-y , @danbp , @modemlooper , @imath , @shanebp .
Jessica
Though its NOT via using functions.php or wp-config.php a solution could be :
Network activate a plugin like Quick Page/Post Redirect Plugin and set it on each sub-site
Request url —> /register/
Destination url —> http://mymainsite.com/register
Have revisted this interesting query!
Consulted this similar query
and have come up with another possible solution
(so long as the main site has a different theme or child theme to the other sites.)
in functions.php of sub-sites’ themes insert
add_action( 'template_redirect', 'redirect_to_specific_page' );
function redirect_to_specific_page() {
if (is_page('Register') && ! is_user_logged_in() ) {
wp_redirect( 'http://yourmainsite.dev/register/', 301 );
exit;
}
}
would not work with slug is_page(‘register’}