dongni8969 2019-04-30 16:10
浏览 34

以编程方式更改URL而不更改页面内容

Is there a way to change the returned url from word press while still rendering the contents of the requested page?

Say I request /dogs/ but need to append a random string to the end of the url while still rendering the page /dogs/

Where /dogs/foobar/ still renders the /dogs/ page

Currently i am using the method as follows

add_action( 'wp', 'url_change' );

function url_change() {
    list($uri, $qs) = explode('?', $_SERVER['REQUEST_URI']);
    global $wp;   
    if(strpos($uri , "dogs") == false) {

    }
    else{
        wp_redirect( $uri . "/foobar/" ,302,'WordPress' );
    }

}

Which displays the correct url, but since its a redirect, it tries to find the page listed at this url. Is there a way to just render the /dogs/ page even with the changed url?

  • 写回答

1条回答 默认 最新

  • duaijiao0648 2019-04-30 21:03
    关注

    Use native php functions:

    header("Location: http://example.com/myOtherPage.php");
    die();
    

    make sure to use die(); http://thedailywtf.com/articles/WellIntentioned-Destruction

    评论

报告相同问题?

悬赏问题

  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)