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?

  • 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?
    – MrWhite
    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. 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.
    – MrWhite
    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! 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.

  • 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.
    – MrWhite
    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. 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).
    – MrWhite
    Apr 19 '14 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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