Forum Moderators: phranque

Message Too Old, No Replies

301 Redirects and Cookie

         

tbrim20

6:24 pm on Jul 2, 2010 (gmt 0)

10+ Year Member



I'm moving my site to a new domain and I currently on the old site use a cookie for returning visitors.

Now since I'm going to be using a 301 redirect using htaccess to map the websites 1 for 1...

I'm wondering if there is a way to set the cookie automatically on the new site so any visitor from the old site will automatically have the cookie set already without having to go through the process to set it again?

I've seen some tricks regarding 302 redirect to the new site that sets the cookie then redirects back to the old site which then would 301 redirect back to the new site.

This would work but only if...
1. SEO would still carry over
2. I could still map the 2 sites page for page.

If this will work, does anyone have an example of how to do it?

Any suggestions are appreciated (even if what I want to do is impossible :))

phranque

8:38 pm on Jul 2, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], tbrim20!

i think this would work:
- you create a script that runs under the old domain and internally rewrite all appropriate requests to this script, redirecting all other requests (images, etc) to the new domain.
- the script looks for a cookie and redirects the request to the new domain with an additional parameter containing the cookie data; if no cookie exists the request is redirected to the new domain otherwise unmolested.
- on the new domain, requests containing the cookie parameter are internally rewritten to another script, which constructs a 301 response redirecting to the "cookieless" url and including the cookie.

to review, this should work thusly for search engines, new visitors and other requests with no cookies:
- "cookieless" request to old domain gets internally rewritten to script
- script 301 redirects request to new domain
(note: you could even use a RewriteCond to test for the cookie and skip the rewrite to script, just redirect to new domain)
- new domain provides a response with a new cookie

and for returning visitors that permit and have a cookie:
- request to old domain gets internally rewritten to script
- script 301 redirects request to new domain with additional cookie parameter
- request to new domain gets internally rewritten to script
- script provides a 301 response with a new cookie and no cookie parameter in the url.
- 2nd request to new domain now includes a cookie

tbrim20

4:18 pm on Jul 19, 2010 (gmt 0)

10+ Year Member



Thanks phranque for answer. I've been trying to make sense of how to implement it but unfortunately haven't come up with my own solution.

I'm new to htaccess and still learning so bear with me. But I've been giving this more thought and I think I've come up with a simpler way to do what I want.

But I would like a little bit of input on how to get this to work (if it is possible). But here is what I was thinking...

1. user visits Old_Domain
2. htaccess checks for "revisit" cookie
3. if cookie is set then redirect to specific page for return visitors on New_Domain
4. if cookie is not set then redirect using 301 to same page on New_Domain

So here are the questions...

1. Can I do this type of cookie based redirect along with the 301 redirect and still transfer all SEO from the Old_Domain?

2. If it's possible, how do I set up the order of operations to check for the cookie first and redirect accordingly?

I would want to use both of the follow (note: _ is only used so it doesn't create a link)...

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) _http://www.newdomain.com/$1 [R=301,L]

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} ^.*cookie-name.*$ [NC]
RewriteRule .* _http://www.newdomain.com/page.html [NC,L]

I'm sure I'll have more questions but thanks for the patience and helping a newbie willing to learn.