最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

url rewriting - Taking a value from PHP_URL_PATH won't work after WordPress 5.5 update

programmeradmin0浏览0评论

A custom WordPress module takes certain int variable directly from the PHP_URL_PATH roughly like this:

private function myIdVariable() {
    $myid = 0;
    // Support both URL formats: /path/123 and /path/?myid=123
    $lastpartofurl = (int) basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
    $myid = (int) isset($_GET['myid']) ? $_GET['myid'] : $lastpartofurl;
    
    return $myid;
}

Here, the /path/ is the SEO optimized path for the post/article where this module is used, and there's no articles in /path/subpath.

Before the WordPress 5.5 update this worked, but now /path/123 gets automatically redirected to /path/. It should result as the same page as /path/?myid=123 for prettier URLs giving better SEO.

Results from the Monkeyman Rewrite Analyzer shows this matches (.?.+?)?(:/([0-9]+))?/?$.

As this code supports two URL formats, there's a workaround by adding a RedirectMatch, e.g.

RedirectMatch ^/path/([0-9]+)$ "/?myid=$1"

However, for a real fix I would like to know:

  1. What might have added this redirection in WordPress 5.5?
  2. Is it configurable?
  3. Is this change in the URL behaviour intended in WordPress 5.5, or should I report a bug?
发布评论

评论列表(0)

  1. 暂无评论