{"id":984,"date":"2018-09-21T16:59:22","date_gmt":"2018-09-21T15:59:22","guid":{"rendered":"https:\/\/www.orchidbox.com\/?p=984"},"modified":"2018-09-21T16:59:22","modified_gmt":"2018-09-21T15:59:22","slug":"htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation","status":"publish","type":"post","link":"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/","title":{"rendered":".Htaccess and 301 Redirects and Rewrite &#8211; SEO Secrets to Indexation"},"content":{"rendered":"<p>301 redirect is the best method to preserve your current search engine rankings when redirecting web pages or a web site. The code &#8220;301&#8221; is interpreted as &#8220;moved permanently&#8221;.<\/p>\n<p>After the code, the URL of the missing or renamed page is noted, followed by a space, then followed by the new location or file name. You implement the 301 redirect by creating a .htaccess file.<\/p>\n<p>When a visitor\/spider requests a web page, your web server checks for a .htaccess file. The .htaccess file contains specific instructions for certain requests, including<br \/>\nsecurity, redirection issues and how to handle certain errors.<\/p>\n<p>1. To create a .htaccess file, open notepad, name and save the file as .htaccess (there is no extension).<\/p>\n<p>2. If you already have a .htaccess file on your server, download it to your desktop for editing.<\/p>\n<p>3. Place this code in your .htaccess file:<br \/>\nredirect 301 \/old\/old.htm https:\/\/www.you.com\/new.htm<\/p>\n<p>4. If the .htaccess file already has lines of code in it, skip a line, then add the above code.<\/p>\n<p>5. Save the .htaccess file<\/p>\n<p>6. Upload this file to the root folder of your server.<\/p>\n<p>7. Test it by typing in the old address to the page you&#8217;ve changed. You should be immediately taken to the new location.<\/p>\n<p><code><br \/>\nRewriteEngine On<\/p>\n<p>RewriteCond %{HTTP_HOST} ^seobook.com [NC]<br \/>\nRewriteRule ^(.*)$ https:\/\/www.seobook.com\/$1 [L,R=301]<br \/>\n<\/code><\/p>\n<p>The &#8216;(*.)$&#8217; says that we&#8217;ll take anything that comes after https:\/\/seobook.com and append it to the end of &#8216;https:\/\/www.seobook.com&#8217; (thats the &#8216;$1&#8217; part) and redirect to that URL. For more grit on how this works checkout a good regular expressions resource or two.<\/p>\n<p>Note: You only have to enter &#8216;RewriteEngine On&#8217; once at the top of your .htaccess file.<\/p>\n<p>Alternately you may chose to do this 301 redirect from<br \/>\nin the Apache config file httpsd.conf.<\/p>\n<p><code><br \/>\n<VirtualHost 67.xx.xx.xx><br \/>\nServerName www.seobook.com<br \/>\nServerAdmin webmaster@seobook.com<br \/>\nDocumentRoot \/home\/seobook\/public_html<br \/>\n<\/VirtualHost><\/p>\n<p><VirtualHost 67.xx.xx.xx><br \/>\nServerName seobook.com<br \/>\nRedirectMatch permanent ^\/(.*) https:\/\/www.seobook.com\/$1<br \/>\n<\/VirtualHost><br \/>\n<\/code><\/p>\n<p>Note that often webhost managers like CPanel would have placed a &#8216;ServerAlias&#8217; seobook.com in the first VirtualHost entry which would negate the following VirtualHost so be sure to remove the non-www ServerAlias.<br \/>\n301 www to non-www<\/p>\n<p>Finally the www 301 redirect to non-www version would look like:<\/p>\n<p><code><br \/>\nRewriteCond %{HTTP_HOST} ^www.seobook.com [NC]<br \/>\nRewriteRule ^(.*)$ https:\/\/seobook.com\/$1 [L,R=301]<br \/>\n<\/code><br \/>\nRedirect All Files in a Folder to One File<\/p>\n<p>Lets say you no longer carry &#8216;Super Hot Product&#8217; and hence want to redirect all requests to the folder \/superhotproduct to a single page called \/new-hot-stuff.php. This redirect can be accomplished easily by adding the following your .htaccess page:<\/p>\n<p><code><br \/>\nRewriteRule ^superhotproduct(.*)$ \/new-hot-stuff.php [L,R=301]<br \/>\n<\/code><\/p>\n<p>But what if you want to do the same as the above example EXCEPT for one file? In the next example all files from \/superhotproduct\/ folder will redirect to the \/new-hot-stuff.php file EXCEPT \/superhotproduct\/tony.html which will redirect to \/imakemoney.html<\/p>\n<p><code><br \/>\nRewriteRule ^superhotproduct\/tony.html \/imakemoney.html [L,R=301]<br \/>\nRewriteRule ^superhotproduct(.*)$ \/new-hot-stuff.php [L,R=301]<br \/>\n<\/code><br \/>\nRedirect a Dynamic URL to a New Single File<\/p>\n<p>It&#8217;s common that one will need to redirect dynamic URL&#8217;s with parameters to single<br \/>\nstatic file:<\/p>\n<p><code><br \/>\nRewriteRule ^article.jsp?id=(.*)$ \/latestnews.htm [L,R=301]<br \/>\n<\/code><\/p>\n<p>In the above example, a request to a dynamic URL such as https:\/\/www.seobook.com\/article.jsp?id=8932<br \/>\nwill be redirected to https:\/\/www.seobook.com\/latestnews.htm<br \/>\nSSL httpss to https<\/p>\n<p>This one is more difficult but I have experienced serious canonicalization problems<br \/>\nwhen the secure httpss version of my site was fully indexed along side my https version. I have yet<br \/>\nto find a way to redirect httpss for the bots only so the only solution I have for now is<br \/>\nto attempt to tell the bots not to index the httpss version. There are only two ways I know to do this and neither are pretty.<\/p>\n<p>1. Create the following PHP file and include it at the top of each page:<\/p>\n<p>if (isset($_SERVER[&#8216;HTTPS&#8217;]) &#038;&#038; strtolower($_SERVER[&#8216;HTTPS&#8217;]) == &#8216;on&#8217;) {<br \/>\necho &#8216;<meta name=\"robots\" content=\"noindex,nofollow\">&#8216;. &#8220;\\n&#8221;;<br \/>\n}<\/p>\n<p>2. Cloak your robots.txt file.<br \/>\nIf a visitor comes from httpss and happens to be one of the known bots such as googlebot, you will display:<\/p>\n<p>User-agent: *<br \/>\nDisallow: \/<\/p>\n<p>Otherwise display your normal robots.txt. To do this you&#8217;ll need to alter your .htaccess<br \/>\nfile treat .txt files as PHP or some other dynamic language and then proceed to write the cloaking code.<\/p>\n<p>I really wish the search engines would get together and add a new attribute to robots.txt that would allow us to stop them from indexing httpss URLs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>301 redirect is the best method to preserve your current search engine rankings when redirecting web pages or a web site. The code &#8220;301&#8221; is interpreted as &#8220;moved permanently&#8221;. After the code, the URL of the missing or renamed page is noted, followed by a space, then followed by the new location or file name. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":985,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,4],"tags":[],"class_list":["post-984","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-content","category-seo"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>.Htaccess and 301 Redirects and Rewrite - SEO Secrets to Indexation - Orchid Box Insights<\/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:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\".Htaccess and 301 Redirects and Rewrite - SEO Secrets to Indexation - Orchid Box Insights\" \/>\n<meta property=\"og:description\" content=\"301 redirect is the best method to preserve your current search engine rankings when redirecting web pages or a web site. The code &#8220;301&#8221; is interpreted as &#8220;moved permanently&#8221;. After the code, the URL of the missing or renamed page is noted, followed by a space, then followed by the new location or file name. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/\" \/>\n<meta property=\"og:site_name\" content=\"Orchid Box Insights\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-21T15:59:22+00:00\" \/>\n<meta name=\"author\" content=\"frank\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"frank\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/\"},\"author\":{\"name\":\"frank\",\"@id\":\"https:\/\/www.orchidbox.com\/insights\/#\/schema\/person\/d0e37cec33581140df37c170d90868db\"},\"headline\":\".Htaccess and 301 Redirects and Rewrite &#8211; SEO Secrets to Indexation\",\"datePublished\":\"2018-09-21T15:59:22+00:00\",\"dateModified\":\"2018-09-21T15:59:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/\"},\"wordCount\":684,\"publisher\":{\"@id\":\"https:\/\/www.orchidbox.com\/insights\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/#primaryimage\"},\"thumbnailUrl\":\"\",\"articleSection\":[\"Content\",\"SEO\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/\",\"url\":\"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/\",\"name\":\".Htaccess and 301 Redirects and Rewrite - SEO Secrets to Indexation - Orchid Box Insights\",\"isPartOf\":{\"@id\":\"https:\/\/www.orchidbox.com\/insights\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/#primaryimage\"},\"thumbnailUrl\":\"\",\"datePublished\":\"2018-09-21T15:59:22+00:00\",\"dateModified\":\"2018-09-21T15:59:22+00:00\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.orchidbox.com\/insights\/#website\",\"url\":\"https:\/\/www.orchidbox.com\/insights\/\",\"name\":\"Orchid Box Insights\",\"description\":\"Whether you&#039;re navigating the intricacies of SEO, exploring the nuances of pay-per-click advertising, or crafting compelling marketing campaigns, our posts are designed to provide you with the knowledge and tools necessary for success. At Orchid Box, we pride ourselves on delivering industry-leading advice that enhances website visibility, engages audiences, and maximizes return on investment. Stay ahead of the curve with our in-depth articles on SEO, PPC, and digital marketing.\",\"publisher\":{\"@id\":\"https:\/\/www.orchidbox.com\/insights\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.orchidbox.com\/insights\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.orchidbox.com\/insights\/#organization\",\"name\":\"Orchid Box\",\"url\":\"https:\/\/www.orchidbox.com\/insights\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.orchidbox.com\/insights\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/wwww.orchidbox.com\/insights\/wp-content\/uploads\/2024\/06\/symbol.png\",\"contentUrl\":\"https:\/\/wwww.orchidbox.com\/insights\/wp-content\/uploads\/2024\/06\/symbol.png\",\"width\":401,\"height\":400,\"caption\":\"Orchid Box\"},\"image\":{\"@id\":\"https:\/\/www.orchidbox.com\/insights\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.orchidbox.com\/insights\/#\/schema\/person\/d0e37cec33581140df37c170d90868db\",\"name\":\"frank\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.orchidbox.com\/insights\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/45b74e4b9bbcfe0dcf2d7dca07222cc3eccf37085a34710d2ec2ea42d00b3c25?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/45b74e4b9bbcfe0dcf2d7dca07222cc3eccf37085a34710d2ec2ea42d00b3c25?s=96&d=mm&r=g\",\"caption\":\"frank\"},\"sameAs\":[\"https:\/\/orchidbox.com\/insights\/\"],\"url\":\"https:\/\/www.orchidbox.com\/insights\/author\/frank\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":".Htaccess and 301 Redirects and Rewrite - SEO Secrets to Indexation - Orchid Box Insights","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:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/","og_locale":"en_US","og_type":"article","og_title":".Htaccess and 301 Redirects and Rewrite - SEO Secrets to Indexation - Orchid Box Insights","og_description":"301 redirect is the best method to preserve your current search engine rankings when redirecting web pages or a web site. The code &#8220;301&#8221; is interpreted as &#8220;moved permanently&#8221;. After the code, the URL of the missing or renamed page is noted, followed by a space, then followed by the new location or file name. [&hellip;]","og_url":"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/","og_site_name":"Orchid Box Insights","article_published_time":"2018-09-21T15:59:22+00:00","author":"frank","twitter_card":"summary_large_image","twitter_misc":{"Written by":"frank","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/#article","isPartOf":{"@id":"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/"},"author":{"name":"frank","@id":"https:\/\/www.orchidbox.com\/insights\/#\/schema\/person\/d0e37cec33581140df37c170d90868db"},"headline":".Htaccess and 301 Redirects and Rewrite &#8211; SEO Secrets to Indexation","datePublished":"2018-09-21T15:59:22+00:00","dateModified":"2018-09-21T15:59:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/"},"wordCount":684,"publisher":{"@id":"https:\/\/www.orchidbox.com\/insights\/#organization"},"image":{"@id":"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/#primaryimage"},"thumbnailUrl":"","articleSection":["Content","SEO"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/","url":"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/","name":".Htaccess and 301 Redirects and Rewrite - SEO Secrets to Indexation - Orchid Box Insights","isPartOf":{"@id":"https:\/\/www.orchidbox.com\/insights\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/#primaryimage"},"image":{"@id":"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/#primaryimage"},"thumbnailUrl":"","datePublished":"2018-09-21T15:59:22+00:00","dateModified":"2018-09-21T15:59:22+00:00","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.orchidbox.com\/insights\/htaccess-and-301-redirects-and-rewrite-seo-secrets-to-indexation\/#primaryimage","url":"","contentUrl":""},{"@type":"WebSite","@id":"https:\/\/www.orchidbox.com\/insights\/#website","url":"https:\/\/www.orchidbox.com\/insights\/","name":"Orchid Box Insights","description":"Whether you&#039;re navigating the intricacies of SEO, exploring the nuances of pay-per-click advertising, or crafting compelling marketing campaigns, our posts are designed to provide you with the knowledge and tools necessary for success. At Orchid Box, we pride ourselves on delivering industry-leading advice that enhances website visibility, engages audiences, and maximizes return on investment. Stay ahead of the curve with our in-depth articles on SEO, PPC, and digital marketing.","publisher":{"@id":"https:\/\/www.orchidbox.com\/insights\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.orchidbox.com\/insights\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.orchidbox.com\/insights\/#organization","name":"Orchid Box","url":"https:\/\/www.orchidbox.com\/insights\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.orchidbox.com\/insights\/#\/schema\/logo\/image\/","url":"https:\/\/wwww.orchidbox.com\/insights\/wp-content\/uploads\/2024\/06\/symbol.png","contentUrl":"https:\/\/wwww.orchidbox.com\/insights\/wp-content\/uploads\/2024\/06\/symbol.png","width":401,"height":400,"caption":"Orchid Box"},"image":{"@id":"https:\/\/www.orchidbox.com\/insights\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.orchidbox.com\/insights\/#\/schema\/person\/d0e37cec33581140df37c170d90868db","name":"frank","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.orchidbox.com\/insights\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/45b74e4b9bbcfe0dcf2d7dca07222cc3eccf37085a34710d2ec2ea42d00b3c25?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/45b74e4b9bbcfe0dcf2d7dca07222cc3eccf37085a34710d2ec2ea42d00b3c25?s=96&d=mm&r=g","caption":"frank"},"sameAs":["https:\/\/orchidbox.com\/insights\/"],"url":"https:\/\/www.orchidbox.com\/insights\/author\/frank\/"}]}},"_links":{"self":[{"href":"https:\/\/www.orchidbox.com\/insights\/wp-json\/wp\/v2\/posts\/984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orchidbox.com\/insights\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orchidbox.com\/insights\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orchidbox.com\/insights\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orchidbox.com\/insights\/wp-json\/wp\/v2\/comments?post=984"}],"version-history":[{"count":0,"href":"https:\/\/www.orchidbox.com\/insights\/wp-json\/wp\/v2\/posts\/984\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.orchidbox.com\/insights\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.orchidbox.com\/insights\/wp-json\/wp\/v2\/media?parent=984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orchidbox.com\/insights\/wp-json\/wp\/v2\/categories?post=984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orchidbox.com\/insights\/wp-json\/wp\/v2\/tags?post=984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}