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

问题描述 投票:-1回答:1

有没有办法在仍然呈现所请求页面的内容的同时更改返回的网址?

假设我请求/ dogs /但需要在URL的末尾添加随机字符串,同时仍然呈现页面/狗/

where / dogs / foobar /仍然呈现/ dogs / page

目前我使用的方法如下

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' );
    }

}

它显示正确的URL,但由于它是重定向,它会尝试查找此URL列出的页面。有没有办法只使用更改的URL呈现/ dogs /页面?

php wordpress
1个回答
-1
投票

使用本机php函数:

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

确保使用die(); http://thedailywtf.com/articles/WellIntentioned-Destruction

© www.soinside.com 2019 - 2024. All rights reserved.