最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Redirect subdomain homepage to domain specific page in wordpress multisite

programmeradmin2浏览0评论

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
Add a comment  | 

2 Answers 2

Reset to default 0

Have 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.

发布评论

评论列表(0)

  1. 暂无评论