Forum Moderators: phranque

Message Too Old, No Replies

htaccess redirect based on cookie

how is it done?

         

Shingetsu

3:12 am on Jan 31, 2011 (gmt 0)

10+ Year Member



Ok. Hi all.
I have a forum that is on sub.domain.com
I have a ad page that is on main domain.com
I Want to set this up so that each time a user goes to sub.domain.com
And he doesn't have cookie named ad with value 1, he gets redirected to the ad page.
Trick here is this:
1. The redirect page has to be ad page.php?redirect=
where you wanted to go.
2. This has to apply to many files, some of which are in folders (which is why I'm trying apache even if I don't know it)

I quickly became confused with the syntax.
Can anyone help please?

Shingetsu

7:09 pm on Jan 31, 2011 (gmt 0)

10+ Year Member



What I need is to set a condition
RewriteCond %{HTTP_COOKIE} [something with cookie I'd and value]
RewriteRule [send to an external http]

Shingetsu

1:36 am on Feb 1, 2011 (gmt 0)

10+ Year Member



Bump

jdMorgan

3:52 am on Feb 1, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Helpers are few.
Patience is a virtue.

RewriteCond %{HTTP_COOKIE} !^ad=1$
RewriteRule ^(.*)$ http://www.example.com/ad-page.php?return=/$1

Here, it is assumed that ad-page.php will display the ad, and set a timed or browser sessions cookie named "ad" to value "1", and then append the value of the Get string named "return" to your domain name and redirect back to it.

Study the documentation cited in our Apache Forum Charter before using this code. If you are in a hurry, then study it longer and harder. Single typos in server config code can and do put companies out of business...

Jim

Shingetsu

3:56 am on Feb 2, 2011 (gmt 0)

10+ Year Member



Yeah, problem here is that the redirect get value in the rewrite rule needs to be defined by js get_URL...
It must be the URL to which the user was trying to go to.

g1smd

9:55 am on Feb 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If that was a question, and if it had made sense, I would have attempted to answer it.

A very clear definition of exactly what you are trying to do, in detail, is a great help.

Shingetsu

4:07 pm on Feb 2, 2011 (gmt 0)

10+ Year Member



Ok.
I am trying of making a rule by witch anyone accessing a server will be checked for a php cookie named ad that contains the value 1.
If they do not have that cookie, then the person gets redirected to example.com/ad?redirect=value where value is the URL to which the user was trying to get to.
If they do have the cookie, nothing happens.

jdMorgan

8:02 pm on Feb 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code I posted above puts the client-requested URL-path into the "return=" variable.

Modify to suit.

Jim