{"id":116,"date":"2020-08-20T14:04:45","date_gmt":"2020-08-20T12:04:45","guid":{"rendered":"https:\/\/wiki.activenet.sk\/?p=116"},"modified":"2020-09-04T08:50:55","modified_gmt":"2020-09-04T06:50:55","slug":"presmerovanie-stranky","status":"publish","type":"post","link":"https:\/\/wiki.activenet.sk\/index.php\/2020\/08\/20\/presmerovanie-stranky\/","title":{"rendered":"Presmerovanie str\u00e1nky"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Setting Up a Permanent 301 Redirect in .htaccess<\/h1>\n\n\n\n<p>A permanent&nbsp;<strong>301 redirect<\/strong>&nbsp;in your&nbsp;<strong>.htaccess<\/strong>&nbsp;file lets search engines and others know that an old link has been replaced by a new one. It\u2019s the recommended method for directing traffic from an existing page.<\/p>\n\n\n\n<p>For developers or sysadmins experienced with the command line, get High Availability and Root Access for your application, service, and websites with&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.inmotionhosting.com\/cloud-vps\" target=\"_blank\">Cloud VPS Hosting<\/a><\/p>\n\n\n\n<p>Some common uses of a&nbsp;<strong>301 .htaccess redirect<\/strong>:<\/p>\n\n\n\n<ul><li><a href=\"https:\/\/www.inmotionhosting.com\/support\/website\/setting-up-a-301-permanent-redirect-via-htaccess\/#individual-files\">Redirect individual files on the same domain<\/a>An old file has moved locations, or the information is now contained in a new file.<\/li><li><a href=\"https:\/\/www.inmotionhosting.com\/support\/website\/setting-up-a-301-permanent-redirect-via-htaccess\/#old-domain-to-new\">Redirect an old domain to a new domain<\/a>You\u2019ve moved a website from an old domain to a new one, and you want any old links to go to the new site.<\/li><li><a href=\"https:\/\/www.inmotionhosting.com\/support\/website\/setting-up-a-301-permanent-redirect-via-htaccess\/#force-www\">Force www. version of domain to be used<\/a>&nbsp;or you can&nbsp;<a href=\"https:\/\/www.inmotionhosting.com\/support\/website\/setting-up-a-301-permanent-redirect-via-htaccess\/#force-non-www\">force non www. version of domain to be used<\/a>Visitors access and link to your website in multiple ways such as&nbsp;<strong>example.com<\/strong>, and&nbsp;<strong>www.example.com<\/strong>&nbsp;and you can set one as the preferred method that your site displays.<\/li><li><a href=\"https:\/\/www.inmotionhosting.com\/support\/website\/setting-up-a-301-permanent-redirect-via-htaccess\/#file-extensions\">Redirect all files with certain extension<\/a>You used to have all of your files using an extension like&nbsp;<strong>.php<\/strong>&nbsp;and have converted everything to&nbsp;<strong>.htm<\/strong>&nbsp;so using a 301 redirect you can update all links to use the new extension.<\/li><\/ul>\n\n\n\n<p>You have the ability to&nbsp;<a href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/cpanel\/cpanel-manage-domains\/setting-up-redirect-cpanel\" target=\"_blank\" rel=\"noreferrer noopener\">setup redirects for a domain in your cPanel<\/a>&nbsp;interface one link at a time. You can also add the redirects manually by modifying your&nbsp;<strong>.htaccess<\/strong>&nbsp;file directly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting to your .htaccess file<\/h2>\n\n\n\n<p>On a Linux server you would&nbsp;<a href=\"https:\/\/www.inmotionhosting.com\/support\/website\/where-is-my-htaccess-file\/\" target=\"_blank\" rel=\"noreferrer noopener\">use your&nbsp;<strong>.htaccess<\/strong>&nbsp;file<\/a>&nbsp;to implement a 301 redirect for your pages.<\/p>\n\n\n\n<p>Click here for steps getting to .htaccess file<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Redirect individual files<\/h2>\n\n\n\n<p>To redirect individual files, like&nbsp;<strong>example.com\/oldfile.htm<\/strong>&nbsp;to&nbsp;<strong>newfile.htm<\/strong>&nbsp;you can use a 301 redirect like this:<code>Redirect 301 \/oldfile.htm \/newfile.htm<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.inmotionhosting.com\/support\/images\/stories\/htaccess\/301-redirect\/single-file-301-redirect.gif\" alt=\"single file 301 redirect\"\/><\/figure>\n\n\n\n<p>To redirect one specific file to another domain such as&nbsp;<strong>example.com\/oldfile.htm<\/strong>&nbsp;to&nbsp;<strong>example.net\/newfile.htm<\/strong>:<code>Redirect 301 \/oldfile.htm https:\/\/example.net\/newfile.htm<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.inmotionhosting.com\/support\/images\/stories\/htaccess\/301-redirect\/single-file-domain-301-redirect.gif\" alt=\"single file domain 301 redirect\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Redirect an old domain to a new domain<\/h2>\n\n\n\n<p>If you had an old domain such as&nbsp;<strong>example.com<\/strong>, and now you decided you actually want to use&nbsp;<strong>example.net<\/strong>&nbsp;for the website. You could setup a 301 redirect for the entire domain, so that old links to&nbsp;<strong>example.com<\/strong>&nbsp;carry over.<\/p>\n\n\n\n<p>Code in the&nbsp;<strong>example.com<\/strong>&nbsp;domain\u2019s&nbsp;<strong>.htaccess<\/strong>&nbsp;file:<code>RewriteEngine on<br>RewriteCond %{HTTP_HOST} ^example.com [NC,OR]<br>RewriteCond %{HTTP_HOST} ^www.example.com [NC]<br>RewriteRule ^(.*)$ https:\/\/example.<strong>net<\/strong>\/$1 [L,R=301,NC]<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.inmotionhosting.com\/support\/images\/stories\/htaccess\/301-redirect\/full-domain-301-redirect.gif\" alt=\"full domain 301 redirect\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Force www. version of domain to be used<\/h2>\n\n\n\n<p>A search engine like Google would see&nbsp;<strong>example.com<\/strong>&nbsp;and&nbsp;<strong>www.example.com<\/strong>&nbsp;as essentially two separate websites. They recommend you pick one version you\u2019d like search engines to display and&nbsp;<a href=\"https:\/\/support.google.com\/webmasters\/answer\/139066?hl=en#301\" target=\"_blank\" rel=\"noreferrer noopener\">using a 301 redirect<\/a>&nbsp;is a possible option.<\/p>\n\n\n\n<p>If you have a lot of links on the web where people are linking to your site as&nbsp;<strong>example.com<\/strong>, but you would like your visitors to instead end up at&nbsp;<strong>www.example.com<\/strong>&nbsp;you can force this version of your domain with these rules:<code>RewriteEngine on<br>RewriteCond %{HTTP_HOST} ^example.com [NC]<br>RewriteRule ^(.*)$ https:\/\/www.example.com\/$1 [L,R=301,NC]<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.inmotionhosting.com\/support\/images\/stories\/htaccess\/301-redirect\/force-www-301-redirect.gif\" alt=\"force www 301 redirect\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Force non www. version of domain to be used<\/h2>\n\n\n\n<p>If you have a lot of links on the web where people are linking to your site as&nbsp;<strong>www.example.com<\/strong>, but you would like your visitors to instead end up at&nbsp;<strong>example.com<\/strong>&nbsp;you can force this version of your domain with these rules:<code>RewriteEngine on<br>RewriteCond %{HTTP_HOST} ^www.example.com [NC]<br>RewriteRule ^(.*)$ https:\/\/example.com\/$1 [L,R=301,NC]<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.inmotionhosting.com\/support\/images\/stories\/htaccess\/301-redirect\/force-non-www-301-redirect.gif\" alt=\"force non www 301 redirect\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Redirect all files with certain extension<\/h2>\n\n\n\n<p>To re-direct all of one type of file to another, such as&nbsp;<strong>example.com\/file.php<\/strong>&nbsp;to&nbsp;<strong>example.com\/file.htm<\/strong><code>RewriteEngine On<br>RewriteCond %{REQUEST_URI} .php$<br>RewriteRule ^(.*).php$ \/$1.htm [R=301,L]<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.inmotionhosting.com\/support\/images\/stories\/htaccess\/301-redirect\/file-extension-301-redirect.gif\" alt=\"file extension 301 redirect\"\/><\/figure>\n\n\n\n<p>You should now know how to properly setup 301 permanent redirects on your website to help ensure that search engines and visitors coming to your site from older links can still get to your new content.This entry was posted in&nbsp;<a href=\"https:\/\/www.inmotionhosting.com\/support\/website\/\">Website<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting Up a Permanent 301 Redirect in .htaccess A permanent&nbsp;301 redirect&nbsp;in your&nbsp;.htaccess&nbsp;file lets search engines and others know that an old link has been replaced by a new one. It\u2019s the recommended method for directing traffic from an existing page. For developers or sysadmins experienced with the command line, get High Availability and Root Access [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/wiki.activenet.sk\/index.php\/wp-json\/wp\/v2\/posts\/116"}],"collection":[{"href":"https:\/\/wiki.activenet.sk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wiki.activenet.sk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wiki.activenet.sk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/wiki.activenet.sk\/index.php\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":1,"href":"https:\/\/wiki.activenet.sk\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":117,"href":"https:\/\/wiki.activenet.sk\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions\/117"}],"wp:attachment":[{"href":"https:\/\/wiki.activenet.sk\/index.php\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wiki.activenet.sk\/index.php\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wiki.activenet.sk\/index.php\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}