How does link redirecting work?

112 views
0

Like I understand hyperlinks, but how do you redirect a link to another link?? Can you be redirected twice?

In: 4

Clicking the link tells the browser to move you to a new page. Upon arrival, that new page can tell you you ought to be at a third page and your browser obleges.

This is a useful mechanism for basic things like if you click a link to http://google.com, you get redirected on google’s end to http**s**://www.google.com, since they want you to use the more secure https protocol.

The most common link redirects are done as “rules” on the server.

For example, let’s say I rename a page on my website for from oldpage.html to newpage.html . I want to ensure that the benefit of any links and traffic looking for oldpage.html end up with newpage.html .

I just have to add a rule for this. On Apache servers this is done in a file called htaccess. These rules are checked whenever a page is requested – before it is loaded. When the server sees the request for oldpage.html it will serve up new page HTML to the user.

You can have multiple redirects too – either subsequent rules in the same file or bouncing users from one server to another. It’s best to have a single redirect if possible.

When you request the page, the server sends back a response packet with a redirect status code. The packet contains the new URI for the resource the client requested. The client can send a request to that URI to access the resource. It’s essentially like getting a letter returned with the message “That guy doesn’t live here anymore. Here’s the address he said he was moving to. Good luck.” scribbled on it.

It’s possible that the server for the redirected URI will also respond with a redirect, if the requested resource has moved again. In that case, the client can just keep following redirects until they either find the resource, get an error response, or just give up because it’s taking too long.