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,639
  • 4
  • 21
  • 38

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
  • 17,324
  • 7
  • 67
  • 87
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,715
  • 5
  • 37
  • 58