尝试观察站点上的特定url,并在此基础上向url添加一个字符串,然后重定向。我正在搜索子字符串'/product/‘,所以它需要是动态的~ish (wordpress multisite,需要在所有站点上工作。
在functions.php中尝试过。不确定如何/何时调用它。
function fancy_redirect() {
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if ( (strpos($actual_link, '/product/') !== false) && (strpos($actual_link, '?start_customizing=yes') === false)) {
header('Location: '. $actual_link . '?start_customizing=yes');
}
}我也在javascript中尝试过,这是在控制台中运行的,但不是实时运行的。
window.onload = function() {
if(location.href.search("/product/") !== -1 && location.href.search("/?start_customizing=yes") === -1) {
window.location = (location.href + "?start_customizing=yes");
}
}发布于 2015-04-29 04:00:03
在这一点上,我不得不同意@wawa的观点。如果将此功能构建到/product/的模板中,则可以将用户重定向到相应的URL
header("Location: http://example.com/product/". $new_location);
die();https://stackoverflow.com/questions/29923713
复制相似问题