Welcome Guest, Not a member yet? Register   Sign In
Redirecting does not remove anchor from the URL
#1
Bug 
(This post was last modified: 04-19-2023, 04:45 AM by Muzikant.)

If an anchor is in the old page, it is still presented after redirecting to the new page, where it does not make sense. An anchor should not be there until it is explicitly added in the redirection rule.



For example return redirect()->to('to'); redirecting http://localhost:8080/from#old-anchor to http://localhost:8080/to#old-anchor, which it should not.

The return redirect()->to('to#new-anchor'); redirecting http://localhost:8080/from to http://localhost:8080/to#new-anchor, which is how it should be.

It is also replacing an old anchor to a new anchor, which is also expected: return redirect()->to('to#new-anchor'); redirecting http://localhost:8080/from#old-anchor to http://localhost:8080/to#new-anchor.

So the only problem is in the first case, when old URL have an anchor, but the new URL does not. The same with the redirectResponse.



return redirect()->route('to'); and return redirect('to'); does not support anchors in the redirection rule, but the bug from the first example is presented. I tested it on a fresh CodeIgniter's 4.3.3 installation on PHP 8.1.12 on my Linux machine.
Reply
#2

(This post was last modified: 04-19-2023, 04:41 AM by kenjis.)

Interesting. It seems the browser puts the fragment.

Workarount:
return redirect()->to('to', null, 'refresh');
Reply
#3

(04-19-2023, 04:37 AM)kenjis Wrote: Workarount:
return redirect()->to('to', null, 'refresh');

Thank you, it works. I hope there will be a bug fix in the upcoming versions if it will be possible.
Reply
#4

This is not a bug. The browser keeps the fragment.
So we can't fix.
Reply
#5

(04-21-2023, 05:12 AM)kenjis Wrote: This is not a bug. The browser keeps the fragment.
So we can't fix.

What about refreshing by default? If it is not a good way to solve it, then your solution could be mentioned in a documentation.
Reply
#6

(04-19-2023, 03:31 AM)Muzikant Wrote: return redirect()->to('to'); redirecting http://localhost:8080/from#old-anchor to http://localhost:8080/to#old-anchor, which it should not.

You say it should not. But why should not?
At least major browsers do so.
Reply
#7

(04-23-2023, 08:09 AM)Muzikant Wrote: What about refreshing by default?

It is a breaking change.

(04-23-2023, 08:09 AM)Muzikant Wrote: If it is not a good way to solve it, then your solution could be mentioned in a documentation.

No problem. Pull Request is welcome.
https://github.com/codeigniter4/CodeIgni...request.md
Reply
#8

(This post was last modified: 04-24-2023, 08:02 AM by Muzikant.)

(04-23-2023, 05:30 PM)kenjis Wrote: You say it should not. But why should not?
At least major browsers do so.

There is a small chance, or at least not certain, that in the new location will be an old anchor. Maybe there is a reason why browsers doing it, but from my point of view it is not an expected behavior.



(04-23-2023, 05:32 PM)kenjis Wrote: No problem. Pull Request is welcome.
https://github.com/codeigniter4/CodeIgni...request.md

Thank you for inviting me, I will consider it. At the moment I am not registered at GitHub, because it is owned by Microsoft.
Reply
#9

Probably redirecting is expected for moving the URI with no content change.

Quote:URL redirection, also known as URL forwarding, is a technique to give more than one URL address to a page, a form, a whole website, or a web application.
https://developer.mozilla.org/en-US/docs...directions
Reply
#10

Hello guys, I think add a notice in documentation is a good solution and I have been sent a new PR for this.
https://github.com/codeigniter4/CodeIgniter4/pull/7450
Reply




Theme © iAndrew 2016 - Forum software by © MyBB