将WP多站点URL重定向到亚物土URL

发布于 2025-02-03 07:04:38 字数 743 浏览 5 评论 0原文

我有一个WordPress多站点安装,其基本URL的https://example.com。子站点的初始URL的https://example.com/forinstance可以在WordPress中更改为https://forinstance.com的别名。

但是我想从https://example.com/caseinpoint也将所有URL重定向到https://forinstance.com。在WordPress中没有办法做到这一点,因此我试图在我的.htaccess文件中执行此操作。我无法正常工作。

我尝试了:

RewriteCond %{HTTPS_HOST} ^example.com/caseinpoint$
RewriteRule (.*)$ https://forinstance.com [R=301,L]

但是它总是在example.com上使用404。

但是,这确实适用于其他子站点:

RewriteCond %{HTTPS_HOST} ^ejemplo.com$
RewriteRule (.*)$ https://perinstanza.com [R=301,L]

因此,这似乎与多站点有关。我如何重定向example.com/forinstance,请?

I have a WordPress multisite installation with a base URL of https://example.com. Subsites have an initial URL of https://example.com/forinstance, which can be changed in WordPress to an alias of https://forinstance.com.

But I want to redirect all URLs from https://example.com/caseinpoint ALSO to https://forinstance.com. There's not a way to do that in WordPress, so I'm trying to do it in my .htaccess file. I can't get it to work though.

I've tried variants of:

RewriteCond %{HTTPS_HOST} ^example.com/caseinpoint$
RewriteRule (.*)$ https://forinstance.com [R=301,L]

But it always just goes to a 404 on example.com.

However, this DOES work for other subsites:

RewriteCond %{HTTPS_HOST} ^ejemplo.com$
RewriteRule (.*)$ https://perinstanza.com [R=301,L]

So it seems to be something to do with the multisite. How can I redirect example.com/forinstance, please?!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

待天淡蓝洁白时 2025-02-10 07:04:38

您发布的两个规则实际上都不会执行任何操作,因为https_host不是有效的服务器变量。它应该是http_host,它代表host http request equest头(因此http _ prefix)。 IE。请求主机名(或)。

主机标头不包括您在第一个规则中试图匹配的URL路径。

大概您想将剩余的URL路径重定向到新域上的同一路径。例如。 https://example.com/caseinpoint/< url>应该重定向到https://forinstance.com/&lt;实际上,您不仅会重定向https://example.com/caseinpoint(缺少tailting slash)为https://forinstance.com/(有如您所说,在主机名之后总是

在这种情况下,您可以在root .htaccess文件的顶部进行以下操作, 任何现有的WordPress指令。

RewriteCond %{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^caseinpoint(?:$|/(.*)) https://forinstance/$1 [R=302,L]

这也允许可选的www子域。

$ 1 BackReference包含Rewriterule 模式,即。 “ caseinpoint/”之后的URL路径(不包括斜线)。

首先使用302(临时)重定向测试,以避免任何潜在的缓存问题。仅更改为301(永久)重定向 - 如果是意图,则一旦您确认它按预期工作。在测试之前,您可能需要清除浏览器缓存。

Neither of the rules you posted will actually do anything since HTTPS_HOST is not a valid server variable. It should be HTTP_HOST, which represents the Host HTTP request header (hence the HTTP_ prefix). ie. the hostname (or domain) being requested.

The Host header does not include the URL-path, which you are trying to match in the first rule.

Presumably you want to redirect the remaining URL-path to the same on the new domain. eg. https://example.com/caseinpoint/<url> should redirect to https://forinstance.com/<url>? You aren't literally just redirecting https://example.com/caseinpoint (missing trailing slash) to https://forinstance.com/ (there is always a slash after the hostname) as you've stated?

In which case you can do something like the following at the top of the root .htaccess file, before any existing WordPress directives.

RewriteCond %{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^caseinpoint(?:$|/(.*)) https://forinstance/$1 [R=302,L]

This also allows for an optional www subdomain.

The $1 backreference contains the value of the first capturing subpattern in the RewriteRule pattern, ie. the URL-path after "caseinpoint/" (not including the slash).

Test first with a 302 (temporary) redirect to avoid any potential caching issues. Only change to a 301 (permanent) redirect - if that is the intention - once you have confirmed it works as intended. You will likely need to clear your browser cache before testing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文