我不知道为什么 Wordpress 会这样工作

I don't know why Wordpress worked follow that way

我对 Wordpress 永久链接有疑问。

这些是我展示问题的步骤:

1) 在 admin > pages 中:我创建了新的页面调用“GoodMorning”并且我在前端有 slug“goodmorning” ,我运行://my_domain/goodmorning会显示本页内容

2) 现在,我 运行 ://my_domain/find-me/goodmorning 它会自动重定向到 ://my_domain/goodmorning

/find-me/ :这是任何名称,并且此文本不存在于 wordpress slug、类别、页面、post、....

请告诉我原因。我希望它在 运行 ://my_domain/find-me/goodmorning.

时显示 404 页面

谢谢大家。

添加这个(到 functions.php)应该停止重定向。

remove_action('template_redirect', 'redirect_canonical');

如果您查看 redirect_canonical here 的文档:

Will also attempt to find the correct link when a user enters a URL that does not exist based on exact WordPress query. Will instead try to parse the URL or query in an attempt to figure the correct page to go to.

根据你的问题,我认为这就是你要阻止的。

如果您需要 redirect_canonical 的其他功能,您可以通过将 false 返回到此过滤器来取消重定向,如下所示:

add_filter('redirect_canonical', '__return_false');

之后您需要刷新永久链接配置:

  1. 在主菜单中找到 "Settings > Permalinks"。
  2. 如果需要向下滚动并单击 "Save Changes"。
  3. 刷新规则和永久链接。