doushuichong2589 2015-12-01 06:46
浏览 22
已采纳

Wordpress如何处理URL?

I encountered this (to me) unfamilliar behavior in Wordpress.

Consider a random site using WordPress with a page called example with no content. This is just a page type post and not a category, tag or any sort of hierarchy. A 404 error is triggered if I append characters after the last "/":

http://example.com/example/abc

I expect that but if I only type numbers after the final "/" no 404 error is triggered. For example loading:

http://example.com/example/1123456

gets me to example page and the numbers are kept in the URL. The numbers have no special meaning in this case. There could be any nuber there, but I would expect it to trigger a 404 as it does on other sites.

Appending numbers to the URL on index or category pages still seems to trigger a 404, but not on posts and pages.

I am wondering wether this is an actual feature of WordPress and if so, then what is its purpose?

  • 写回答

3条回答 默认 最新

  • dongtui2029 2015-12-16 20:30
    关注

    This is as designed. Wordpress matches URL's through the built-in rewrite module. You can read about it here. In addition, the source code to follow what is happening with this process is located in wp-content/class-wp-rewrite.php.

    The specific line that provides the behavior you are seeing is below.

    [(.?.+?)(?:/([0-9]+))?/?$] => index.php?pagename=$matches[1]&page=$matches[2]
    

    This code will match on page/post-name, and any following number (this supports pagination). However, it will not match on non-characters after the post name. What is interesting is that even if the post does not have the specified page, it will still accept as legit.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划