Is HTML redirect obsolete?

I heard that the usual way of redirecting from an HTML page, for example

<meta http-equiv="REFRESH" content="0;url=page.html"> 

deprecated by the latest HTML. Is this true or not, and if so, what other ways to redirect?

+4
source share
4 answers

The correct way to redirect is to send redirect headers . You need to change the status from 200 OK to the corresponding status 3xx . Then you also need to include the Location: http://yourRedirectURL header Location: http://yourRedirectURL . The implementation depends on which programming language you use in the background.

+5
source

Using the Location header is a seamless and more efficient way to redirect someone to another page, assuming you use a timeout of zero anyway.

If you donโ€™t place them on the landing page and then redirect them, use the Location header.

I should also note that the location header indicates that it should be provided with a complete landing address and not use an absolute or relative path based on the site. For instance.

 Location: http://www.google.com/ 

Instead:

 Location: /login Location: ../../home 
+2
source

If you use php, you can use the following code (before any other exit to the browser):

 <?php header('Location: http://example.com'); ?> 
+2
source

This is not technically recommended, but this is because the pseudo-term โ€œobsoleteโ€ is casually used in the โ€œspecโ€. The meta redirect mechanism is described as "should not" in HTML 4.01 :

"Note: Some user agents support the use of META to refresh the current page in a specified number of seconds with the option of replacing it with a different URI. Authors should not use this method to redirect users to different pages, as this makes the page inaccessible to some users. Instead, automatic forwarding pages should be done using server-side redirects. "

HTML5 templates, however, describe the meta-processing mechanism, not to mention such things, although the examples are about different use cases. This is no better. It should not be used to redirect an address to a new one, unless you cannot influence the server behavior in order to have the appropriate HTTP redirection. In this case, it is recommended to add a normal link to the new address in the body of the document, in situations where the meta-redirect does not work.

+1
source

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


All Articles