{"id":6361,"date":"2016-02-28T20:04:10","date_gmt":"2016-02-29T01:04:10","guid":{"rendered":"https:\/\/themespress.ca\/?p=6361"},"modified":"2022-09-10T18:34:17","modified_gmt":"2022-09-10T22:34:17","slug":"how-to-do-a-301-redirect-with-wordpress","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/how-to-do-a-301-redirect-with-wordpress\/","title":{"rendered":"How to do a 301 Redirect with WordPress"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>With this tutorial, we will show you how to redirect a template page with <strong><a href=\"https:\/\/codex.wordpress.org\/Plugin_API\/Action_Reference\/template_redirect\" target=\"_blank\" rel=\"noopener\">template_redirect<\/a><\/strong>.<\/p>\n<p>Let&#8217;s say we have a WordPress called Rank and it&#8217;s slug is rank. <\/p>\n<p><strong>Where do I find my page&#8217;s slug?<\/strong> <\/p>\n<p>To find the page slug, open the page in question in your Admin and you&#8217;ll find the modifiable slug under the page&#8217;s title. Like in the image below:<\/p>\n\n\t\t<\/div>\n\t<\/div>\n\n\t<div  class=\"wpb_single_image wpb_content_element vc_align_left wpb_content_element\">\n\t\t\n\t\t<figure class=\"wpb_wrapper vc_figure\">\n\t\t\t<div class=\"vc_single_image-wrapper   vc_box_border_grey\"><img decoding=\"async\" width=\"392\" height=\"147\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-classement.jpg\" class=\"vc_single_image-img attachment-full\" alt=\"\" title=\"Slug WordPress\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-classement.jpg 392w, https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-classement-300x113.jpg 300w, https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-classement-768x288.jpg 768w, https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-classement-1320x495.jpg 1320w, https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-classement-600x225.jpg 600w, https:\/\/themespress.ca\/wp-content\/uploads\/2017\/02\/wsi-imageoptim-classement-450x168.jpg 450w\" sizes=\"(max-width: 392px) 100vw, 392px\" \/><\/div>\n\t\t<\/figure>\n\t<\/div>\n\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>So in this example, I want to redirect my page rank to rank-top-100:<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Redirection de page WordPress en 301<\/h2>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>In your function.php file, add the template_redirect mechanic and use the <strong>via_redirect_page<\/strong> function.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-9621452\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-9621452\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">add_action( &#039;template_redirect&#039;, &#039;via_redirect_page&#039; );\nfunction via_redirect_page() {\n\tif ( is_page(&#039;classement&#039;) &amp;&amp; ! is_user_logged_in() ) {\n\t\twp_redirect( &#039;http:\/\/meilleurstubes.com\/classement\/top-100\/&#039;, 301 ); \n\t\t exit();\n\t}\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>We can now test the redirect to make sure it works. Don&#8217;t forget the exit() or die() after a wp_redirect().<\/p>\n<p>Just remember that the redirect will not work if you&#8217;re connected with your Admin credentials as we specified that redirects do not work when logged it. Or either log out, use a different browser or private browser.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"With this tutorial, we will show you how to redirect a template page with template_redirect. Let's say we have a WordPress called Rank and it's slug is rank. Where do<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/how-to-do-a-301-redirect-with-wordpress\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4509,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[342],"class_list":["post-6361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-redirects"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6361"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6361\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4509"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}