Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect is keeping hash

For some reason when I redirect with header("Location") the new page keeps the hash.

So if you're 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? ie example.com/account.html


Note:

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

RewriteRule ^([a-zA-Z0-9-_.]+)\.html$ $1.php [L]
like image 529
Steve Robbins Avatar asked Sep 14 '12 21:09

Steve Robbins


People also ask

What is the purpose of redirect?

The general purpose of redirect is to rehabilitate the witness and to explain or rebut any adverse proof, whether direct, circumstantial or inferential that arose during cross-examination.

Are redirects safe?

However, you need to be sure anywhere you do redirects, they are done safely – otherwise you are putting your users in harm's way by enabling phishing attacks. Modern web-mail services are very good at spotting spam and other types of malicious messages.


1 Answers

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

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

However, this behavior isn't guaranteed across the board. It seems to work in WebKit and IE9 in my quick test. Nevertheless, you've stumbled on a black hole in the HTTP specification.

like image 127
N Rohler Avatar answered Sep 19 '22 16:09

N Rohler