【问题标题】:Wordpress Timber plugin custom routes throwing 404Wordpress Timber 插件自定义路由抛出 404
【发布时间】:2021-04-25 20:57:04
【问题描述】:

当我的自定义路线卷曲时,木材路线会抛出 404,如下所示。 GoogleBots 也将其视为 404 页。

λ curl -I http://mysite.test/this-is-a-test/

结果:

HTTP/1.1 404 Not Found
Date: Fri, 23 Apr 2021 03:44:00 GMT
Server: Apache/2.4.39 (Win64) OpenSSL/1.1.1b PHP/7.3.8
Strict-Transport-Security: max-age=31536000
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Link: <http://mysite.test/wp-json/>; rel="https://api.w.org/"
Content-Type: text/html; charset=UTF-8

虽然它在浏览器中运行良好。

我该如何解决这个问题?任何帮助将不胜感激。谢谢

代码示例

Routes::map('this-is-a-test/', function ($params) {
    http_response_code(200);
    echo 'Done'; // I also tried Routes::load('test.php', $params); both shows same result
    exit;
});

【问题讨论】:

  • 您能粘贴一些代码作为路线设置的示例吗?
  • 添加代码示例

标签: wordpress twig wordpress-theming timber


【解决方案1】:

您需要添加 Routes::load 方法才能使路由工作:

Routes::map('this-is-a-test/', function($params){
    Routes::load('file.php', $params, $query, 200);
});

参见 Timber documentation 和依赖项,Upstatement RoutesAltoRouter,这需要 php 文件路径。

【讨论】:

  • 即使使用加载方法λ curl -I http://mysite.test/this-is-a-test/,结果也是404@
  • 我已经更新了我的答案,以使其更清晰,并在干净的安装上进行了测试。确保在你的 functions.php 中快速执行代码,并且不要将其挂钩到 init 或其他操作,否则它可能会被调用太晚
猜你喜欢
  • 2019-01-24
  • 2013-04-01
  • 2017-06-05
  • 1970-01-01
  • 1970-01-01
  • 2021-02-03
  • 1970-01-01
  • 2016-08-04
  • 2016-01-09
相关资源
最近更新 更多