I currently have in my .htaccess:

RewriteRule ^$ http://chfmaine.com/ [CO=moved:yes:chfmaine.com:1/,R=301,NE,NC,L]

I was basing this off of this post.

That's a lot more than I need but the setting of the cookie should be the same. Maybe I am misunderstanding the domain part of the cookie. If I set it to CHFmaine.com shouldn’t that be where it works?

I tried adding the cookie after the 301. Ether way the 301 works but no cookie is passed. This is redirecting from maine-horse-trails.com to chfmaine.com. I have 23 of these for all the different pages that were on the old site. Anything landing at this .htaccess will be redirected and the cookie should be set. So if there is a way to first pass the cookie to anyone then proceed onto the matching rewrite that would be helpful. But if I can get this way to work I dont mind using copy and paste to get it on all the possibilities. and I do not want to pass any queries in the URL.

My question is, what am I doing wrong here? Why can I not find this cookie after a successful redirect? And is there a better option?

  • 1
    Well, you are setting the cookie while still on maine-horse-trails.com so it's not going to be available on chfmaine.com?
    – Pekka
    Dec 12, 2013 at 3:33
  • possible duplicate of How can I set a cookie and then redirect in PHP?
    – EPICWebDesign
    Dec 12, 2013 at 3:33
  • Sorry, I failed to mention that this is set in the .htaccess. not php. I would have to create a large number of directories and other stuff to make the 23 redirects I need due to the way the old site was set up.
    – JpaytonWPD
    Dec 12, 2013 at 3:44
  • chrome shows this Set-Cookie: moved=yes; path=/; domain=.chfmaine.com; expires=Thu, 12-Dec-2013 03:51:41 GMT But that cookie is not set at all
    – JpaytonWPD
    Dec 12, 2013 at 3:56

1 Answer 1


You can't find the cookie after a redirect because the cookie is never set. The redierect happens in Apache, before any PHP or other code is run.

You could use a PHP redirect. For example, land on the page, set the cookie, then redirect.

See this question for more information. https://stackoverflow.com/questions/612034/how-can-i-set-a-cookie-and-then-redirect-in-php

Also, cookies are domain specific. If you set a cookie on one site, it doesn't carry over to the next. Depending on what you're using the cookie for, a $_GET may be a better option.

  • $_GET would work but for SEO it will mess things up. All it is doing is displaying a message to the user reminding them to update links. and PHP redirects would be a lot of work to generate and maintain. there are 23 all in the form of /somepath/someother/. I would have to create 46 directories plus the 23 redirects.
    – JpaytonWPD
    Dec 12, 2013 at 3:49
  • In that case, you could likely make one PHP file that reads the $SERVER['HTTP_HOST'] and acts accordingly. Use .htaccess to forward all relevant requests to that file. Why do you need to set the cookie?
    – EPICWebDesign
    Dec 12, 2013 at 18:42
  • A cookie seems to be the only way I can pass a variable when a user is redirected. It just triggers a script that changes the notification div from display none to block
    – JpaytonWPD
    Dec 12, 2013 at 22:26
  • 1
    A cookie by design won't work since it's a different domain. You'll have to use either a GET or a POST. If you don't want it to appear in the url, use POST. Either way, you'll likely have to use PHP or another scripting language.
    – EPICWebDesign
    Dec 13, 2013 at 19:13
  • The first 3 paragraphs are irrelevant - the actual answer is in the last paragraph: "cookies are domain specific". What you are trying to do is set a cookie on one website from another - cross domain browser security - the browser won't allow this.
    – MrWhite
    Jun 22, 2015 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.