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']);
        }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题