{"id":1386,"date":"2011-08-24T20:40:52","date_gmt":"2011-08-25T03:40:52","guid":{"rendered":"https:\/\/daveworks.net\/web-design-development-tips\/?p=1386"},"modified":"2011-12-14T22:16:53","modified_gmt":"2011-12-15T06:16:53","slug":"how-to-redirect-your-website","status":"publish","type":"post","link":"https:\/\/daveworks.net\/web-design-development-tips\/web-development\/how-to-redirect-your-website\/","title":{"rendered":"How to Redirect Your Website"},"content":{"rendered":"<p><strong>Do you want to have your website automatically redirect to another site or specific page?<\/strong> (read on)<\/p>\n<p><img decoding=\"async\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%27130%27%20height%3D%27152%27%20viewBox%3D%270%200%20130%20152%27%3E%3Crect%20width%3D%27130%27%20height%3D%27152%27%20fill-opacity%3D%220%22%2F%3E%3C%2Fsvg%3E\" data-orig-src=\"https:\/\/daveworks.net\/web-design-development-tips\/wp-content\/uploads\/redirect-website.png\" alt=\"301 Redirect Website image\" title=\"301 Redirect Website\" width=\"130\" height=\"152\" class=\"lazyload alignright size-full wp-image-1393\" \/>Redirects are fairly simple. BUT you need to know what type of file types you are using (php, asp, cfm, etc.) OR if your webhost uses to &#8220;<a href=\"\/web-design-development-tips\/web-development\/how-to-redirect-your-website#redirect_video\" title=\"How to create a redirect via cPanel\">cPanel<\/a>&#8221; you can this without knowing code.(<a href=\"\/web-design-development-tips\/web-development\/how-to-redirect-your-website#redirect_video\" title=\"How to create a redirect via cPanel\">watch quick video<\/a>)  One important note to consider when doing this is to not only think about the redirect but how the search engines will treat the redirect.  Most folks want to get (and keep) the best search results they can and implementing <strong><em>redirects can affect those search results<\/em><\/strong>.  Google and the others look very carefully at redirects to make sure that their results point to valid content.  <strong>How do implement correctly?<\/strong>  <strong>&#8220;301 Redirects&#8221;<\/strong>  (The 301 tells search engines that the page has *permanently* moved to a new location and keeps your search engine results in tact) There are other redirect types, but for this post, we&#8217;ll just deal with 301s.<\/p>\n<h3>So What Exactly Do I Need to Do To Correctly Redirect My Site?? <\/h3>\n<p><!--more Read On to Correctly Create Redirects --><\/p>\n<p>Below are snippets of code <em>(by script\/file type) <\/em>to place at the very top of your homepage: (These snippets are for those who are <strong>not <\/strong> using content management systems like WordPress. Most likely you&#8217;ll need to implement the redirect via <a href=\"#htaccess\" title=\"How to create a redirect via cPanel\">.htaccess<\/a>, either manually or via <a href=\"#video\" title=\"How to create a redirect via cPanel\">cPanel<\/a>)<\/p>\n<h3>PHP Redirect<\/h3>\n<p>&lt;?php<br \/>\nheader( &#8220;HTTP\/1.1 301 Moved Permanently&#8221; );<br \/>\nheader( &#8220;location: https:\/\/www.thenewsite.com&#8221; );<br \/>\n?&gt;<\/p>\n<h3>.NET Redirect<\/h3>\n<p>&lt;script runat=&#8221;server&#8221;&gt;<br \/>\nprivate void Page_Load(object sender, System.EventArgs e)<br \/>\n{<br \/>\nResponse.Status = &#8220;301 Moved Permanently&#8221;;<br \/>\nResponse.AddHeader(&#8220;Location&#8221;,&#8221;https:\/\/www.thenewsite.com&#8221;);<br \/>\n}<br \/>\n&lt;\/script&gt; <\/p>\n<h3>Ruby on Rails Redirect<\/h3>\n<p>def old_action<br \/>\nheaders[&#8220;Status&#8221;] = &#8220;301 Moved Permanently&#8221;<br \/>\nredirect_to &#8220;https:\/\/www.thenewsite.com&#8221;<br \/>\nend <\/p>\n<h3>ASP Redirect<\/h3>\n<p>&lt;%@ Language=VBScript %&gt;<br \/>\n&lt;%<br \/>\nResponse.Status=&#8221;301 Moved Permanently&#8221;<br \/>\nResponse.AddHeader &#8220;Location&#8221;,&#8221;https:\/\/www.thenewsite.com&#8221;<br \/>\n%&gt; <\/p>\n<h3>JSP Redirect<\/h3>\n<p>&lt;%<br \/>\nresponse.setStatus(301);<br \/>\nresponse.setHeader( &#8220;Location&#8221;, &#8220;https:\/\/www.thenewsite.com&#8221; );<br \/>\nresponse.setHeader( &#8220;Connection&#8221;, &#8220;close&#8221; );<br \/>\n%&gt; <\/p>\n<h3>PERL \/ CGI  Redirect<\/h3>\n<p>$q = new CGI;<br \/>\nprint $q-&gt;redirect(&#8220;https:\/\/www.thenewsite.com&#8221;); <\/p>\n<p><a name=\"htaccess\"><\/a><\/p>\n<h3>.htaccess Redirect<\/h3>\n<p>You can also do an .htaccess redirect (copy and paste the code below into a new file as save as &#8220;.htaccess&#8221;) This single file, uploaded to the root directory of your website will redirect all directories and page files from your existing domain to the new domain.<\/p>\n<p>Options +FollowSymLinks<br \/>\nRewriteEngine on<br \/>\nRewriteRule (.*) https:\/\/www.thenewsite.com\/$1 [R=301,L]<\/p>\n<p>*Notes:<br \/>\n<em>Replace the &#8220;www.thenewsite.com&#8221; in the above code with your actual domain name.<br \/>\nThis works ONLY on Linux servers with the Apache Mod-Rewrite moduled enabled. (talk to your webhost to verify)<\/em><\/p>\n<h3>Plain HTML <\/h3>\n<p>*If for whatever reason (as a last resort) you can only redirect a flat html page, please do the folowing &#8220;Meta Refresh&#8221;  (I mention this because Google doesn&#8217;t really like it)  ;)<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta http-equiv=&#8221;refresh&#8221; content=&#8221;0;URL=https:\/\/whatever.com&#8221;&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<\/p>\n<p><a name=\"redirect_video\"><\/a><\/p>\n<h3>Create Redirects via Cpanel<\/h3>\n<p><small>(video courtesy of <a href=\"https:\/\/www.youtube.com\/user\/LearningCPanel\" rel=\"nofollow\" title=\"Video Courtesty of LearningCPanel\">LearningCPanel<\/a>)<\/small><br \/>\n<iframe class=\"lazyload\" width=\"560\" height=\"345\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%27560%27%20height%3D%27345%27%20viewBox%3D%270%200%20560%20345%27%3E%3Crect%20width%3D%27560%27%20height%3D%27345%27%20fill-opacity%3D%220%22%2F%3E%3C%2Fsvg%3E\" data-orig-src=\"https:\/\/www.youtube.com\/embed\/AyQikvf40FM\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do you want to have your website automatically redirect to&hellip; <a class=\"continue\" href=\"https:\/\/daveworks.net\/web-design-development-tips\/web-development\/how-to-redirect-your-website\/\">Continue Reading<span> How to Redirect Your Website<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[264,265,393,392,261,260,262,263],"class_list":["post-1386","post","type-post","status-publish","format-standard","hentry","category-web-development","tag-301-redirect","tag-301-redirect-website","tag-how-to-redirect-my-website","tag-how-to-redirect-website-how-to-redirect-website","tag-how-to-redirect-your-homepage","tag-how-to-redirect-your-website","tag-redirect-website","tag-redirecting-webpage-to-another-webpage"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/daveworks.net\/web-design-development-tips\/wp-json\/wp\/v2\/posts\/1386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daveworks.net\/web-design-development-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daveworks.net\/web-design-development-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daveworks.net\/web-design-development-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daveworks.net\/web-design-development-tips\/wp-json\/wp\/v2\/comments?post=1386"}],"version-history":[{"count":30,"href":"https:\/\/daveworks.net\/web-design-development-tips\/wp-json\/wp\/v2\/posts\/1386\/revisions"}],"predecessor-version":[{"id":1791,"href":"https:\/\/daveworks.net\/web-design-development-tips\/wp-json\/wp\/v2\/posts\/1386\/revisions\/1791"}],"wp:attachment":[{"href":"https:\/\/daveworks.net\/web-design-development-tips\/wp-json\/wp\/v2\/media?parent=1386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daveworks.net\/web-design-development-tips\/wp-json\/wp\/v2\/categories?post=1386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daveworks.net\/web-design-development-tips\/wp-json\/wp\/v2\/tags?post=1386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}