When the page refreshes and i have updated the url with JavaScript history.pushState(), i get the 404 error because it just sends me to a url that doesn't exist but window.onpopstate() works fine when i press the back button.
Essentially what i want to do is ignore the url with PHP/JavaScript, reload the website main page and parse the url as a string into the JavaScript so then i can load the page inside JavaScript based on the parsed url. I'm sure there is a name to this hence i see it all the time in websites, but i searched for like 30 minutes already and its always sending me to the wrong things.