Link to home
Start Free TrialLog in
Avatar of sypder
sypder

asked on

Tracking IP change from HTTP to HTTPS

We track users on our website based on IP address, and lately we have noticed some incorrect tracking information. I believe this is because when someone switches from http to https their IP address changes. Is it possible to append this line in .htaccess to have the old IP address. Here is what I have now:

# switch to httpS if secure directory resources requested using http
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^secure/(.*)$ https://www.thenaughtybag.com/secure/$1 [R=301,L,NE]

I would want something like

# switch to httpS if secure directory resources requested using http
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^secure/(.*)$ https://www.thenaughtybag.com/secure/$1<& or ?>{REMOTE_ADDR} [R=301,L,NE]

Thanks
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

If someone's IP address is changing, it is not likely to be because they are using SSL vs non-SSL.  They are most likely using a proxy server (like AOL) to browse the web.  In this scenario, their IP could change to anything from one connection to the next, and there is not really a feasible way to track it 100%.

You most certainly could append the original IP to a rewrite request, but I don't think that will help you much in this regard.  There are no guarantees that the new IP is the exact same user since a proxy will handle requests from potentially thousands of people.  
Avatar of sypder
sypder

ASKER

Thanks routinet. Because this is only in our final checkout stage, I don't think we will have that many IPs, so having overlap shouldn't be a big problem.

How can I do <& or ?> in .htaccess, otherwise is the code I have above correct?
You'll want to use the [QSA] modifier for the RewriteRule.  Check it out at:

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule
Avatar of sypder

ASKER

My question has never answered. I know how to use the rewrite rule. (I use it in my question). My question has how to control wether a & or a ? is used in the rewrite rule.
>>> My question has never answered.

Did you read my last response?  More importantly, did you read the information found at the link I provided?  Even more importantly, did you read the section of the [QSA] modifier found at the link I provided?


Avatar of sypder

ASKER

I don't see how it would work in this situation.

Can you give me an example?

RewriteRule ^secure/(.*)$ https://www.thenaughtybag.com/secure/$1<& or ?>{REMOTE_ADDR} [R=301,L,NE,QSA]
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sypder

ASKER

Okay,

This is what I didn't get. I didn't know that QSA was smart enough to relieze that after {REMOTE_ADDR} that it needed to start with a & and not a ?

Thanks.