doulao2916 2017-04-28 03:16
浏览 44
已采纳

Wordpress - 将404s迁移到不同的域

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

The challenge/issue is that we have links in the wild referencing www (ex 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).

So if we create a /pricing page in the wordpress site, then its available at www.example.com/pricing and handled by 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. I'm finding some plugins that handle "known" routes but I basically need to have a wildcard redirect but for 404's only.

Let me know if additional details are necessary.

  • 写回答

1条回答 默认 最新

  • douding7189 2017-04-28 03:21
    关注

    Have a look at the Redirection plugin. It has a 404 log, and also supports 301 redirects using specified links or regular expression matching.

    Edit having re-read your requirements, you should be able to just add the following snippet to your theme's functions.php file.

    This will intercept the WordPress lifecycle after a query has been resolved, but before a template is rendered. 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.

    add_action('template_redirect', function () {
        if (! is_admin() && is_404()) {
            header('Location: https://app.example.com' . $_SERVER['REQUEST_URI']);
        }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化