{"id":3484,"date":"2016-02-08T08:13:07","date_gmt":"2016-02-08T08:13:07","guid":{"rendered":"https:\/\/cpanelplesk.com\/wp62\/?p=3484"},"modified":"2021-02-06T09:13:44","modified_gmt":"2021-02-06T09:13:44","slug":"how-to-set-up-a-permanent-301-redirect-using-php","status":"publish","type":"post","link":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/","title":{"rendered":"How to Set up a permanent 301 redirect using PHP"},"content":{"rendered":"<p><span style=\"color: #000000;\">PHP 301 Redirect Permanently is used for diverting visitors from one page to other page or different sites. This is helpful for that page which you need to expel from your site and put new pages or replacing old domain with new domain. With the 301 permanent redirect search engines indexes new url or domain and removed old from their indexing.<!--more--><\/span><\/p>\n<p><span style=\"color: #000000;\">To <a href=\"https:\/\/cpanelplesk.com\/wp62\/creating-301-redirects-with-wordpress\/\">redirect<\/a> users to other domain use following code in php script.<\/span><\/p>\n<div class=\"command-sh\">\n<pre class=\"pretty\">&lt;?php\r\nheader(\"HTTP\/1.1 301 Moved Permanently\");\r\nheader(\"Location: http:\/\/www.other-website.com\");\r\n?&gt;<\/pre>\n<\/div>\n<p><span style=\"color: #000000;\">On same domain if you want to\u00a0redirect users from old.php to new.php, Edit old.php and put following code at top of file:<\/span><\/p>\n<div class=\"command-sh\">\n<pre class=\"lang:default decode:true \">&lt;?php\r\nheader(\"HTTP\/1.1 301 Moved Permanently\");\r\nheader(\"Location: http:\/\/mydomain.com\/new.php\");\r\n?&gt;<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>PHP 301 Redirect Permanently is used for diverting visitors from one page to other page or different sites. This is helpful for that page which you need to expel from your site and put new pages or replacing old domain with new domain. With the 301 permanent redirect search engines indexes new url or domain [&#8230;]<\/p>\n<p><a class=\"understrap-read-more-link\" href=\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/\">Continue Reading&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":3485,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,14],"tags":[],"class_list":["post-3484","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpanel","category-linux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Set up a permanent 301 redirect using PHP - cPanel Plesk<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"How to Set up a permanent 301 redirect using PHP - cPanel Plesk\" \/>\n<meta name=\"twitter:description\" content=\"PHP 301 Redirect Permanently is used for diverting visitors from one page to other page or different sites. This is helpful for that page which you need to expel from your site and put new pages or replacing old domain with new domain. With the 301 permanent redirect search engines indexes new url or domain [...]Continue Reading...\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2016\/02\/301-redirect.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Farooq Omer\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/\"},\"author\":{\"name\":\"Farooq Omer\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13\"},\"headline\":\"How to Set up a permanent 301 redirect using PHP\",\"datePublished\":\"2016-02-08T08:13:07+00:00\",\"dateModified\":\"2021-02-06T09:13:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/\"},\"wordCount\":106,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13\"},\"image\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2016\/02\/301-redirect.jpg\",\"articleSection\":[\"Cpanel\",\"Linux\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/\",\"url\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/\",\"name\":\"How to Set up a permanent 301 redirect using PHP - cPanel Plesk\",\"isPartOf\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2016\/02\/301-redirect.jpg\",\"datePublished\":\"2016-02-08T08:13:07+00:00\",\"dateModified\":\"2021-02-06T09:13:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#primaryimage\",\"url\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2016\/02\/301-redirect.jpg\",\"contentUrl\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2016\/02\/301-redirect.jpg\",\"width\":300,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cpanelplesk.com\/wp62\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Set up a permanent 301 redirect using PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#website\",\"url\":\"https:\/\/cpanelplesk.com\/wp62\/\",\"name\":\"cPanel Plesk\",\"description\":\"Blog on famous hosting control panels\",\"publisher\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cpanelplesk.com\/wp62\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13\",\"name\":\"Farooq Omer\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2020\/11\/cpanelplesk.png\",\"contentUrl\":\"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2020\/11\/cpanelplesk.png\",\"width\":300,\"height\":44,\"caption\":\"Farooq Omer\"},\"logo\":{\"@id\":\"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/cpanelplesk.com\/wp62\/author\/fokado\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Set up a permanent 301 redirect using PHP - cPanel Plesk","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/","twitter_card":"summary_large_image","twitter_title":"How to Set up a permanent 301 redirect using PHP - cPanel Plesk","twitter_description":"PHP 301 Redirect Permanently is used for diverting visitors from one page to other page or different sites. This is helpful for that page which you need to expel from your site and put new pages or replacing old domain with new domain. With the 301 permanent redirect search engines indexes new url or domain [...]Continue Reading...","twitter_image":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2016\/02\/301-redirect.jpg","twitter_misc":{"Written by":"Farooq Omer","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#article","isPartOf":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/"},"author":{"name":"Farooq Omer","@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13"},"headline":"How to Set up a permanent 301 redirect using PHP","datePublished":"2016-02-08T08:13:07+00:00","dateModified":"2021-02-06T09:13:44+00:00","mainEntityOfPage":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/"},"wordCount":106,"commentCount":0,"publisher":{"@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13"},"image":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2016\/02\/301-redirect.jpg","articleSection":["Cpanel","Linux"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/","url":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/","name":"How to Set up a permanent 301 redirect using PHP - cPanel Plesk","isPartOf":{"@id":"https:\/\/cpanelplesk.com\/wp62\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#primaryimage"},"image":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2016\/02\/301-redirect.jpg","datePublished":"2016-02-08T08:13:07+00:00","dateModified":"2021-02-06T09:13:44+00:00","breadcrumb":{"@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#primaryimage","url":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2016\/02\/301-redirect.jpg","contentUrl":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2016\/02\/301-redirect.jpg","width":300,"height":300},{"@type":"BreadcrumbList","@id":"https:\/\/cpanelplesk.com\/wp62\/how-to-set-up-a-permanent-301-redirect-using-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cpanelplesk.com\/wp62\/"},{"@type":"ListItem","position":2,"name":"How to Set up a permanent 301 redirect using PHP"}]},{"@type":"WebSite","@id":"https:\/\/cpanelplesk.com\/wp62\/#website","url":"https:\/\/cpanelplesk.com\/wp62\/","name":"cPanel Plesk","description":"Blog on famous hosting control panels","publisher":{"@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cpanelplesk.com\/wp62\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/c78ae1cf9451a09592fb9697d69c0c13","name":"Farooq Omer","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/image\/","url":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2020\/11\/cpanelplesk.png","contentUrl":"https:\/\/cpanelplesk.com\/wp62\/wp-content\/uploads\/2020\/11\/cpanelplesk.png","width":300,"height":44,"caption":"Farooq Omer"},"logo":{"@id":"https:\/\/cpanelplesk.com\/wp62\/#\/schema\/person\/image\/"},"url":"https:\/\/cpanelplesk.com\/wp62\/author\/fokado\/"}]}},"_links":{"self":[{"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/posts\/3484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/comments?post=3484"}],"version-history":[{"count":0,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/posts\/3484\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/media\/3485"}],"wp:attachment":[{"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/media?parent=3484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/categories?post=3484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelplesk.com\/wp62\/wp-json\/wp\/v2\/tags?post=3484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}