Короч, проще. У меня было header('Location: ...'), а я сделал header('Refresh: 0 URL=...') - страница записывается в историю, я из истории беру ID сообщения, профит!
если вдруг нужен быдлокод, то вот как я сделал.
function idChange(elem, jump) {
var hash;
if (location.hash){
hash = location.hash.split("#")[1];
}
if (elem)
hash = elem;
if (hash) {
var wrapper = document.getElementsByClassName("wrapper");
if (wrapper[0].id == hash)
wrapper[0].id = "main";
else
wrapper[0].id = hash;
history.replaceState({}, document.title, window.location.href.split("#")[0]);
}
if (jump) {
const url = new URL(document.referrer);
document.getElementById("p" + url.searchParams.get("post")).scrollIntoView({block: "start", inline: "nearest", behavior: "smooth"});
}
}