使用 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 时会导致错误。我怎样才能让它工作?

谢谢!

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

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/6103.html

大家都在问