Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does CodeIgniter redirect not remove the hash/pound (#) at the end of the URL?

Tags:

codeigniter

I am not sure if this is really a CodeIgniter issue or a browser issue. This happens in Chrome, but not Safari. However, I would assume it should not be happening in any browser.

If you go to example.com/foo# that contains

redirect('bar');

you would expect to end up at example.com/bar. Instead, you end up at example.com/bar#. I don't understand why the hash does not go away. It makes no sense. What is going on?

like image 539
burger Avatar asked Feb 19 '12 05:02

burger


2 Answers

Use the refresh method if you need to drop the hash:

redirect('bar', 'refresh');
like image 117
dtrenz Avatar answered Oct 02 '22 13:10

dtrenz


it can't. The hash tag is only accessible by a client side script. Code Igniter, PHP or any other server side script won't even know what is after the # sign. The request sent to the server is that before the # sign. The part after #sign is passed to the document to interpret. If there is an element with the id as the # sign, the page scrolls down to it. Otherwise js can read it and do things with it as you desire.

Also, an HTTP redirect transfers the request with the same parameters as the original page, so the hastag is also passed on

like image 26
SoWhat Avatar answered Oct 02 '22 12:10

SoWhat