2

I'm navigating away from a page that has a URL similar to

http://solo.dev/module-1/behavioural-safety/?id=7#14

by using

if($course_id != $_GET['id']) {
    header("location: /courses/");
}

However, it persists the #14 value as

http://solo.dev/courses/#14

How do I redirect to just /courses/ without retaining the hashed value?

Jack hardcastle
  • 2,748
  • 4
  • 22
  • 40

2 Answers2

1

You can specify empty hash instead:

header("location: /courses/#");

Then, on courses/ site you check if there's an empty hash and remove it using JavaScript:

history.pushState('', document.title, window.location.pathname);
Daniel Kmak
  • 18,164
  • 7
  • 66
  • 89
0

Try this will work as simple as that,

header('location: /courses#');

for empty hash you can do this,

window.location.hash = '';
window.location.href = "http://yoururl.com"
Sagar Naliyapara
  • 3,971
  • 5
  • 41
  • 61