I have a wordpress multisite with one site to domain and another to materials.domain
At the domain site I have a page domain/materials
I'd like to redirect the materials.domain homepage to the domain/materials
I'm using a child theme to my subdomain instalation and trying the following on functions.php
wp_redirect(home_url(''),301);
exit;
Now when I access the materials.domain the showed url is ://domain/materials/
What i'm doing wrong? How can I achieve the correct redirection?
I have a wordpress multisite with one site to domain and another to materials.domain
At the domain site I have a page domain/materials
I'd like to redirect the materials.domain homepage to the domain/materials
I'm using a child theme to my subdomain instalation and trying the following on functions.php
wp_redirect(home_url('https://domain/materials'),301);
exit;
Now when I access the materials.domain the showed url is https://materials.domain/https://domain/materials/
What i'm doing wrong? How can I achieve the correct redirection?
Share Improve this question edited May 25, 2020 at 6:51 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked May 25, 2020 at 4:01 user1301037user1301037 836 bronze badges 1- Welcome to WordPress Development. I hope you find the answer(s) you are looking for (I have added what I think is the answer). Our site is different from most - if you have not done so yet, consider checking out the tour and help center to find out how things work. – Matthew Brown aka Lord Matt Commented Jun 6, 2020 at 15:58
2 Answers
Reset to default 0Have you tried creating the redirect within the CPanel of wherever your website is being hosted from? I manage all of my redirects there, rather than from within my functions.php. There's a really simple guide on doing that here.
Or is there a specific reason that you would like the redirect to be within the functions.php?
The problem is here:
wp_redirect(home_url('https://domain/materials'),301);
home_url
adds the home URL to the start of the link. In your case you get something as if you had gone:
$out = "https://materials.domain/" . "https://domain/materials/";
Instead, try this:
wp_redirect('https://domain/materials',301);
exit;
that will send the user to the link without the part you do not want.