php - 使用 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
。我怎样才能让它工作?
谢谢!
解决方案
推荐阅读
- json - 应用程序脚本 JSON.parse() 返回意外结果,我该如何解决?
- java - 找不到添加到我的自定义库的库
- python - 如何使用模运算符在 Python 中打印非序列数
- typescript - 如何让vscode检测路径intellisense中的.native.js和.web.js文件?
- powershell - 如何使 Powershell 提取元数据脚本运行得更快?
- python-3.x - Python:从不同线程运行许多子进程很慢
- javascript - 如何在 JEST 中模拟 toJSON() 函数?
- c# - 起订量设置以行使字符串的通用类型调用返回
- docker - 与 docker swarm 中的所有节点共享大文件
- javascript - React-NextJS - TypeError:无法读取未定义的属性“味道”