{"id":32143,"date":"2014-09-04T10:26:02","date_gmt":"2014-09-04T15:26:02","guid":{"rendered":"http:\/\/webirix.com\/?p=32143"},"modified":"2015-06-08T08:01:16","modified_gmt":"2015-06-08T13:01:16","slug":"redireccionar-a-otra-pagina-web-con-php","status":"publish","type":"post","link":"https:\/\/webirix.com\/en\/redireccionar-a-otra-pagina-web-con-php\/","title":{"rendered":"Redirect to another web page with php"},"content":{"rendered":"<h2 style=\"color: #303030;\"><a href=\"http:\/\/webirix.com\/wp-content\/uploads\/2014\/05\/elephpant.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-30277 aligncenter\" src=\"http:\/\/webirix.com\/wp-content\/uploads\/2014\/05\/elephpant.png\" alt=\"elephpant\" width=\"238\" height=\"153\" srcset=\"https:\/\/webirix.com\/wp-content\/uploads\/2014\/05\/elephpant.png 397w, https:\/\/webirix.com\/wp-content\/uploads\/2014\/05\/elephpant-300x192.png 300w\" sizes=\"auto, (max-width: 238px) 100vw, 238px\" \/><\/a><\/h2>\n<h2 style=\"color: #303030;\">Simple redirection<\/h2>\n<p><b style=\"color: #303030;\">To redirect the visitor to another page<\/b><span style=\"color: #303030;\">\u00a0(especially useful in a conditional loop), just use the following code:\u00a0<\/span><\/p>\n<pre style=\"color: #324354;\">&lt;?php\r\nheader('Location: mipagina.php');\r\n?&gt;\r\n<\/pre>\n<p><br style=\"color: #303030;\" \/><span style=\"color: #303030;\">Where\u00a0<\/span><i style=\"color: #303030;\">my page<\/i><span style=\"color: #303030;\">\u00a0represents the address of the page to which you want to redirect. This address can be absolute and can have parameters of the form\u00a0<\/span><i style=\"color: #303030;\">mypage.php? param1 = val1\u00b6m2 = val2<\/i><span style=\"color: #303030;\">).\u00a0<\/span><br style=\"color: #303030;\" \/><a style=\"color: #3487bc;\" name=\"ruta-relativa-absoluta\"><\/a><\/p>\n<h2 style=\"color: #303030;\">Relative \/ absolute path<\/h2>\n<p><span style=\"color: #303030;\">Theoretically, it is better to prefer an absolute path from the server root (DOCUMENT_ROOT), as follows:\u00a0<\/span><\/p>\n<pre style=\"color: #324354;\">&lt;?php\r\nheader('Location: \/repertoire\/mapage.php');\r\n?&gt;\r\n<\/pre>\n<p><br style=\"color: #303030;\" \/><span style=\"color: #303030;\">If the landing page is on another server, then indicate the full URL, as follows:\u00a0<\/span><\/p>\n<pre style=\"color: #324354;\">&lt;?php\r\nheader(&#039;Location: <a style=\"color: #3487bc;\" href=\"http:\/\/www.commentcamarche.net\/forum\/\">http:\/\/www.commentcamarche.net\/forum\/');<\/a>\r\n?&gt;\r\n\r\n<\/pre>\n<p>HTTP headers<\/p>\n<p><span style=\"color: #303030;\">Redirects are HTTP headers. But, according to the HTTP protocol, HTTP headers must be sent before any other type of content, which means that no characters must be sent before the call of the header function, not even a space!\u00a0<\/span><br style=\"color: #303030;\" \/><br style=\"color: #303030;\" \/><span style=\"color: #303030;\">In other words,\u00a0<\/span><b style=\"color: #303030;\">the header () function must necessarily be used before any HTML code<\/b><span style=\"color: #303030;\">.\u00a0<\/span><br style=\"color: #303030;\" \/><br \/>\nTemporary \/ permanent redirects<\/p>\n<p><span style=\"color: #303030;\">By default, the type of redirect presented above is a temporary redirect. Which means that search engines like Google don&#039;t take it into account for rankings.\u00a0<\/span><br style=\"color: #303030;\" \/><br style=\"color: #303030;\" \/><span style=\"color: #303030;\">Therefore, if we want to indicate to search engines that page A is now in location B, we must use the following code at the beginning of the PHP file corresponding to page A:\u00a0<\/span><\/p>\n<pre style=\"color: #324354;\">&lt;?\r\nheader('Status: 301 Moved Permanently', false, 301);\r\nheader('Location: direccion_de_la_pagina_B);\r\n?&gt;\r\n<\/pre>\n<p>Interpretation of PHP code<\/p>\n<p><span style=\"color: #303030;\">The PHP code located after the call to the header () function will be interpreted by the server, even if the visitor has already left the address specified in the redirection, which means that in most cases we will be interested in putting the exit function () after the header () function to not make the server work for pleasure:\u00a0<\/span><\/p>\n<pre style=\"color: #324354;\">&lt;?\r\nheader('Status: 301 Moved Permanently', false, 301);\r\nheader('Location: direccion);\r\nexit();\r\n?&gt;<\/pre>","protected":false},"excerpt":{"rendered":"<p>Simple redirection To redirect the visitor to another page (especially useful in a conditional loop), just use the following code: Where mypage represents the address of the page to which you want to redirect. This address can be absolute and can have parameters of the form mypage.php? Param1 = val1\u00b6m2 = val2). Relative \/ absolute path Theoretically, it is better to prefer ...<\/p>","protected":false},"author":2,"featured_media":30277,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2013,2014],"tags":[],"class_list":["post-32143","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-disenoweb","category-programacionweb"],"jetpack_featured_media_url":"https:\/\/webirix.com\/wp-content\/uploads\/2014\/05\/elephpant.png","_links":{"self":[{"href":"https:\/\/webirix.com\/en\/wp-json\/wp\/v2\/posts\/32143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webirix.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webirix.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webirix.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/webirix.com\/en\/wp-json\/wp\/v2\/comments?post=32143"}],"version-history":[{"count":2,"href":"https:\/\/webirix.com\/en\/wp-json\/wp\/v2\/posts\/32143\/revisions"}],"predecessor-version":[{"id":37367,"href":"https:\/\/webirix.com\/en\/wp-json\/wp\/v2\/posts\/32143\/revisions\/37367"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webirix.com\/en\/wp-json\/wp\/v2\/media\/30277"}],"wp:attachment":[{"href":"https:\/\/webirix.com\/en\/wp-json\/wp\/v2\/media?parent=32143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webirix.com\/en\/wp-json\/wp\/v2\/categories?post=32143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webirix.com\/en\/wp-json\/wp\/v2\/tags?post=32143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}