微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 WordPress 插件中的目录在 URL 上生成自定义输出

如何解决使用 WordPress 插件中的目录在 URL 上生成自定义输出

我正在尝试创建一个自定义 URL,我将在其中输出一些字符串。问题是我希望这个 URL 包含一个 /.well-kNown/ 目录,当我这样做时,会发生 403 禁止错误。所以我当前的代码在没有目录的情况下工作,而不是在 /.well-kNown/ 目录下工作。这是我的代码

add_action('parse_request','custom_output');
function custom_output() {            
    global $wp;
    global $wp_query;
    $urlEnd = 'custom-output'; // This will work
    $desiredUrlEnd = '.well-kNown/custom-output'; // This will not work
    
    if (!$wp_query->is_main_query()) {
        return;
    }

    if ($wp->request === $desiredUrlEnd) {
        $wp_query->set($desiredUrlEnd,1);
    }

    if ($wp_query->get($desiredUrlEnd)) {
        @ini_set('display_errors',0);
        @header('Cache-Control: no-cache');
        @header('X-Robots-Tag: noindex,follow');

        echo 'custom output';
        exit;
    }
}

所以它适用于 $urlEnd 并且输出显示https://example.com/custom-output 上,但它不适用于 $desiredUrlEnd 并且在我访问 https://example.com/.well-kNown/custom-output 时会导致错误。我怎样才能让它工作?

谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。