将WP多站点URL重定向到亚物土URL
我有一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发布的两个规则实际上都不会执行任何操作,因为
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指令。这也允许可选的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 beHTTP_HOST
, which represents theHost
HTTP request header (hence theHTTP_
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 tohttps://forinstance.com/<url>
? You aren't literally just redirectinghttps://example.com/caseinpoint
(missing trailing slash) tohttps://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.This also allows for an optional www subdomain.
The
$1
backreference contains the value of the first capturing subpattern in theRewriteRule
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.