Redirect Store Hash

For some reason, when I redirect from header("Location") , the new page saves the hash.

So if you are on example.com/index.html#signup

I redirect with

 header("Location: /account.html"); exit; 

But then it shows example.com/account.html#signup

Why is this happening and how can I stop it? those. example.com/account.html


Note:

I am using .htaccess to redirect file.html to file.php

 RewriteRule ^([a-zA-Z0-9-_.]+)\.html$ $1.php [L] 
+4
source share
2 answers

The simple answer to the question "how to stop it" is to specify an empty hash in the Location header:

 header('Location: /account.html#'); 

However, this behavior is not guaranteed in all directions. It seems to work in WebKit and IE9 in my quick test. However, you stumbled upon a black hole in the HTTP specification .

+4
source

I am looking for an answer that works in Firefox. After some time, surfing here and there, while my cat holds meow, he leads me to a final decision:

die('<script> window.location='your-url-without-hash';</script>');

Sometimes you want to reserve a hash, sometimes not, and because the cross browser matters, it’s better to control the client browser to reload and kill the hash.

+1
source

Source: https://habr.com/ru/post/1434305/


All Articles