{"id":1731,"date":"2024-12-27T08:06:43","date_gmt":"2024-12-27T08:06:43","guid":{"rendered":"https:\/\/donhit.com\/en\/?p=1731"},"modified":"2024-12-27T08:10:27","modified_gmt":"2024-12-27T08:10:27","slug":"redirect-code-generator","status":"publish","type":"post","link":"https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/","title":{"rendered":"Redirect Code Generator"},"content":{"rendered":"<p><center><div class=\"container123\">\r\n        <h2>Google Traffic Redirect Generator<\/h2>\r\n        \r\n        <p class=\"description\">\r\n            Generate custom redirect code that only redirects visitors from Google search results based on your specified percentage. Visitors from other sources will not be affected.\r\n        <\/p>\r\n\r\n        <div class=\"form-group\">\r\n            <label for=\"redirectUrl\">Redirect URL:<\/label>\r\n            <input type=\"text\" \r\n                   id=\"redirectUrl\" \r\n                   placeholder=\"Enter your URL here (Example: https:\/\/website.com)\"\r\n                   value=\"\">\r\n        <\/div>\r\n\r\n        <div class=\"form-group\">\r\n            <label for=\"redirectRate\">Redirect Rate (%):<\/label>\r\n            <div class=\"range-container\">\r\n                <input type=\"number\" \r\n                       id=\"redirectRate\" \r\n                       min=\"0\" \r\n                       max=\"100\" \r\n                       value=\"100\"\r\n                       onchange=\"updateRate(this.value)\">\r\n                <span class=\"rate-display\" id=\"rateDisplay\">100% of Google traffic will be redirected<\/span>\r\n            <\/div>\r\n        <\/div>\r\n\r\n        <button onclick=\"generateCode()\">Generate Code<\/button>\r\n\r\n        <div class=\"output\" id=\"output\">\r\n            <pre><code id=\"codeOutput\"><\/code><\/pre>\r\n            <button class=\"copy-btn\" onclick=\"copyCode()\">Copy Code<\/button>\r\n            <p class=\"success-message\" id=\"copySuccess\">Code copied!<\/p>\r\n        <\/div>\r\n    <\/div>\r\n\r\n    <script>\r\n        \/\/ Same JavaScript code as before\r\n        function updateRate(value) {\r\n            const rate = Math.min(Math.max(0, value), 100);\r\n            document.getElementById('redirectRate').value = rate;\r\n            document.getElementById('rateDisplay').textContent = \r\n                `${rate}% of Google traffic will be redirected`;\r\n        }\r\n\r\n        function validateUrl(url) {\r\n            try {\r\n                new URL(url);\r\n                return true;\r\n            } catch {\r\n                return false;\r\n            }\r\n        }\r\n\r\n        function generateCode() {\r\n            const redirectUrl = document.getElementById('redirectUrl').value.trim();\r\n            const redirectRate = document.getElementById('redirectRate').value;\r\n            \r\n            if (!redirectUrl) {\r\n                alert('Please enter a redirect URL');\r\n                return;\r\n            }\r\n\r\n            if (!validateUrl(redirectUrl)) {\r\n                alert('Please enter a valid URL (Example: https:\/\/website.com)');\r\n                return;\r\n            }\r\n\r\n            if (redirectRate < 0 || redirectRate > 100) {\r\n                alert('Please enter a rate between 0 and 100');\r\n                return;\r\n            }\r\n\r\n            const code = `<!-- Conditional Redirect Code -->\r\n<script>\r\n(function() {\r\n    \/\/ Check if visitor is coming from Google\r\n    function isFromGoogle() {\r\n        var referrer = document.referrer;\r\n        return referrer.toLowerCase().includes('google.com');\r\n    }\r\n\r\n    \/\/ Generate random number between 0 and 100\r\n    function getRandomPercentage() {\r\n        return Math.random() * 100;\r\n    }\r\n\r\n    \/\/ Perform redirect if visitor is from Google and within specified percentage\r\n    if (isFromGoogle() && getRandomPercentage() <= ${redirectRate}) {\r\n        window.location.href = \"${redirectUrl}\";\r\n    }\r\n})();\r\n<\\\/script>`;\r\n\r\n            document.getElementById('codeOutput').textContent = code;\r\n            document.getElementById('output').classList.add('show');\r\n        }\r\n\r\n        function copyCode() {\r\n            const codeText = document.getElementById('codeOutput').textContent;\r\n            navigator.clipboard.writeText(codeText).then(() => {\r\n                const successMsg = document.getElementById('copySuccess');\r\n                successMsg.style.display = 'block';\r\n                setTimeout(() => {\r\n                    successMsg.style.display = 'none';\r\n                }, 2000);\r\n            }).catch(err => {\r\n                alert('Failed to copy code. Please try again.');\r\n            });\r\n        }\r\n    <\/script>\r\n<\/center><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[186],"tags":[],"class_list":["post-1731","post","type-post","status-publish","format-standard","hentry","category-coder"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Redirect Code Generator - DonHit<\/title>\n<meta name=\"description\" content=\"Generate custom redirect code that only redirects visitors from Google search results based on your specified percentage. Visitors from other sources will not be affected.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Redirect Code Generator - DonHit\" \/>\n<meta property=\"og:description\" content=\"Generate custom redirect code that only redirects visitors from Google search results based on your specified percentage. Visitors from other sources will not be affected.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/\" \/>\n<meta property=\"og:site_name\" content=\"DonHit - World of Tools\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-27T08:06:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-12-27T08:10:27+00:00\" \/>\n<meta name=\"author\" content=\"DonHit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DonHit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Redirect Code Generator - DonHit","description":"Generate custom redirect code that only redirects visitors from Google search results based on your specified percentage. Visitors from other sources will not be affected.","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:\/\/donhit.com\/en\/coder\/redirect-code-generator\/","og_locale":"en_US","og_type":"article","og_title":"Redirect Code Generator - DonHit","og_description":"Generate custom redirect code that only redirects visitors from Google search results based on your specified percentage. Visitors from other sources will not be affected.","og_url":"https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/","og_site_name":"DonHit - World of Tools","article_published_time":"2024-12-27T08:06:43+00:00","article_modified_time":"2024-12-27T08:10:27+00:00","author":"DonHit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"DonHit","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/#article","isPartOf":{"@id":"https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/"},"author":{"name":"DonHit","@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148"},"headline":"Redirect Code Generator","datePublished":"2024-12-27T08:06:43+00:00","dateModified":"2024-12-27T08:10:27+00:00","mainEntityOfPage":{"@id":"https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/"},"wordCount":9,"commentCount":0,"publisher":{"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148"},"articleSection":["Coder"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/","url":"https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/","name":"Redirect Code Generator - DonHit","isPartOf":{"@id":"https:\/\/donhit.com\/en\/#website"},"datePublished":"2024-12-27T08:06:43+00:00","dateModified":"2024-12-27T08:10:27+00:00","description":"Generate custom redirect code that only redirects visitors from Google search results based on your specified percentage. Visitors from other sources will not be affected.","breadcrumb":{"@id":"https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/donhit.com\/en\/coder\/redirect-code-generator\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Trang ch\u1ee7","item":"https:\/\/donhit.com\/en\/"},{"@type":"ListItem","position":2,"name":"Coder","item":"https:\/\/donhit.com\/en\/category\/coder\/"},{"@type":"ListItem","position":3,"name":"Redirect Code Generator"}]},{"@type":"WebSite","@id":"https:\/\/donhit.com\/en\/#website","url":"https:\/\/donhit.com\/en\/","name":"DonHit - World of tools","description":"","publisher":{"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/donhit.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148","name":"DonHit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/donhit.com\/en\/wp-content\/uploads\/2024\/11\/logo-donhit.webp","contentUrl":"https:\/\/donhit.com\/en\/wp-content\/uploads\/2024\/11\/logo-donhit.webp","width":400,"height":267,"caption":"DonHit"},"logo":{"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/image\/"},"description":"DonHit is a website designed to provide useful tools for everyone. Its primary goal is to support and empower the community. All the tools available on the site are completely free to use.","sameAs":["https:\/\/donhit.com\/en"],"url":"https:\/\/donhit.com\/en\/author\/admin_don\/"}]}},"_links":{"self":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts\/1731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/comments?post=1731"}],"version-history":[{"count":1,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts\/1731\/revisions"}],"predecessor-version":[{"id":1732,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts\/1731\/revisions\/1732"}],"wp:attachment":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/media?parent=1731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/categories?post=1731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/tags?post=1731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}