Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need a .htaccess redirect rule that redirects visitors to a url only if the visitor is logged into google.

I was thinking of doing it by looking into cookies

RewriteEngine On
RewriteCond %{REQUEST_URI} /ingoing*$
RewriteCond %{HTTP_COOKIE} !^.*GOOGLE-COOKIE.*$ [NC]
RewriteRule . example.com/outgoing [R,L]

What sting does a Google cookie only contain if a user is logged in?

share|improve this question
Simply "logged into Google"? Or authenticated on your site using their Google (openId/Oauth) account? On which domain are you wanting to check for cookies? – w3dk Apr 18 '14 at 19:04
Simply logged into Google. I need to check the cookies on my domain, from which I will then redirect the user based on the service he is logged into. I just need a rule that will tell - is user logged into Google - yes/no. – Marek Andreansky Apr 18 '14 at 19:05
There is no way to do this simply by checking cookies. (Even) Google is not able to set cross-domain cookies (ie. on your domain) and you cannot check cookies on another domain. You might be able to do this via a scripted solution using a Google API, but this is in the realms of OAuth and the user is likely to be (should) prompted for authorisation. Any other method is going to be a hack. – w3dk Apr 18 '14 at 19:29
I've found a way on how to do it with a script, have a look at my answer if you're interested. And thanks for your help! – Marek Andreansky Apr 18 '14 at 23:47

I've solved it by using a script that redirects the user if he is logged into G+.

I've scavenged the script from this site

The explanation on how the script works can be found here.

share|improve this answer
Thanks for the feedback. That's certainly very interesting, but very "hacky" ;) That example page doesn't appear to detect anything for me in Google Chrome, however, Opera and Firefox appear to play along. – w3dk Apr 19 '14 at 0:09
For me it works on Chrome perfectly, tried it yesterday and everything is working so far. Only problem is that the direct link to G+ reviews does not work on mobile devices, have to do some more research for that. – Marek Andreansky Apr 19 '14 at 11:50
It seems that the script does require 3rd party cookies to be enabled in the browser. In Google Chrome 3rd party cookies are disabled by default (which is why it's not working for me). – w3dk Apr 19 '14 at 20:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.