Redirecting a user but not Googlebot to solve problem with iFrames in content

Redirecting a user but not Googlebot to solve problem with iFrames in content - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Redirecting a user but not Googlebot to solve problem with iFrames in content error on your web browser. Problem :


TLDR



To work around a problem with a third party documentation writing software I need to redirect a page to another page but only if a user in browser is looking at it. I want the google bot to see the original page but the user to see the redirected page.



The webpages are hosted as raw HTML/css/javascript on a server with no .htaccess. I can only use Javascript to do the redirect.



I have good legitimate, non-spammy reasons to do so. Any solutions welcome!






The longer detail



Documentation writing software that I am using outputs pages that look like this:



enter image description here



It is structured (by the Documentation software) to be a Treeview with table of contents on the left, then an iFrame on the right hosting the actual content.



As a result, google bot cannot see or crawl the actual content from the iFrame version. Instead it crawls the inner page hosted in the iframe, which is here:



enter image description here



That would be fine but now when a user clicks on a link in google:



enter image description here



... they are taken to the page above (no iFrame, no nice tree view) so are unaware any other documentation exists.



To workaround this I've put a short in place which displays a button at the top of the page prompting the user to redirect to the iFrame version.



enter image description here



I'd much rather have an auto redirect though, which would give a better user experience, but I need to preserve Google seeing the original page to ensure that the site gets indexed.


Solution :

This is high risk practice.
IMHO... You will sooner or later probably get banned in google because of sneaky redirects. Are you sure you want to try it anyway?



if (!(/bot|googlebot/i.test(navigator.userAgent))) 
document.location.href="UrlToBeRedirectedIfNotGoogleBot";



JavaScript code above relies on navigator.userAgent variable.
We are preparing regular expression with words "bot" and "googlebot", that is case insensitive (/i modifier thou). Then we are testing navigator.userAgent variable if it matches. Exclamation mark negates this result, so code in curly braces is being executed only if userAgent does not match regular expression.



document.location.href="..."; is one of standard methods of redirecting in JavaScript. There might be another way of doing it which would better suit your needs.


We hope that this article has helped you resolve the redirects, googlebot, javascript error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=