2

I am creating a gateway page that redirects visitors based on what services they are using.

How should a .htaccess rule that redirects a visitor if he has a cookie originating from the domain accounts.google.com look like?

RewriteEngine On
RewriteCond %{REQUEST_URI} /ingoing*$
RewriteCond %{HTTP_COOKIE} ?? WHAT SHOULD I PUT HERE ??[NC]
RewriteRule . example.com/outgoing [R,L]
1

2 Answers 2

9

You cannot do this because you can only see cookies from the domain that your site is on. The browser will NOT send you any cookies from other domains.

3
  • +1 for nice answer, If browser would allow to read cookies for cross domain then there would be major security problem. :) Apr 19, 2014 at 6:19
  • What if I added a Google Maps iframe to my website? When I am logged into Google Maps I see my profile picture on the top right corner of the map, this could work (unless iframes have hidden cookies).
    – SkyHiRider
    Apr 19, 2014 at 11:53
  • You will not be able to run your own code in that iframe (if we're talking about JS). You need to read a bit on how the HTTP protocol works. Apr 19, 2014 at 16:44
0

In the end you are asking for instructions for session hijacking. There are ways that might work, but once you are detected any search engine will kick your site out of their index as an attack site.

Though there is a simple solution: If you want to know if the new user found your site through Google or another search engine check the referer. Since you are using mod_rewrite search the Apache Docs for HTTP_REFERER.

2
  • I want to create a gateway page - if the user is logged into Google I want him to be redirected to the Google Review page, otherwise he should be redirected to a general review page.
    – SkyHiRider
    Apr 18, 2014 at 21:01
  • 1
    As Florin Asavoaie pointed out: no legal way to get that cookie. Apr 18, 2014 at 21:06

Not the answer you're looking for? Browse other questions tagged .