[英]Wordpress - Migrate 404s to different domain
Backstory, I've got a "php/symfony web app" that is currently hosted on www.example.com
but I'm wanting to have that whole functionality be moved to app.example.com
so I can spin up a wordpress site that handles all of the www
traffic (its our marketing pages). 背景故事,我目前在
www.example.com
托管了一个“ php / symfony Web应用程序”,但我希望将整个功能移至app.example.com
以便我可以启动一个wordpress网站处理所有www
流量(其营销页面)。
The challenge/issue is that we have links in the wild referencing www
(ex www.example.com/thing/handled/by/app
). 面临的挑战/问题是,我们在
www
www.example.com/thing/handled/by/app
引用中有链接(例如www.example.com/thing/handled/by/app
)。 So I need to find a wordpress plugin that will issue 301's for anything it doesn't know how to handle (aka wp needs to have 404 redirect to app
). 因此,我需要找到一个wordpress插件,对不知道如何处理的任何东西发出301通知(aka wp需要将404重定向到
app
)。
So if we create a /pricing
page in the wordpress site, then its available at www.example.com/pricing
and handled by wordpress. 因此,如果我们在wordpress网站上创建
/pricing
页面,则可以在www.example.com/pricing
找到该页面并由wordpress处理。 But if someone goes to www.example.com/foo
which is not a page wordpress is able to handle, then we have a 301 to app.example.com/foo
. 但是,如果有人访问了
www.example.com/foo
而不是wordpress能够处理的页面,那么app.example.com/foo
为301。 I'm finding some plugins that handle "known" routes but I basically need to have a wildcard redirect but for 404's only. 我找到了一些处理“已知”路由的插件,但是我基本上需要通配符重定向,但仅适用于404。
Let me know if additional details are necessary. 让我知道是否需要其他详细信息。
Have a look at the Redirection plugin . 看一下Redirection插件 。 It has a 404 log, and also supports 301 redirects using specified links or regular expression matching.
它具有404日志,还支持使用指定链接或正则表达式匹配的301重定向。
Edit having re-read your requirements, you should be able to just add the following snippet to your theme's functions.php file. 编辑有重读你的要求,你应该能够只是下面的代码片段添加到您的主题的functions.php文件。
This will intercept the WordPress lifecycle after a query has been resolved, but before a template is rendered. 在查询解决之后,但在呈现模板之前,这将拦截WordPress生命周期。 If the request is not for a page in the admin panel and it is resolved to a 404, then it will redirect the request to your app instead.
如果该请求不是针对管理面板中的页面的,而是已解析为404,则它将将该请求重定向到您的应用。
add_action('template_redirect', function () {
if (! is_admin() && is_404()) {
header('Location: https://app.example.com' . $_SERVER['REQUEST_URI']);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.