Jump to content

Recommended Posts

Have a site, and when people come to it, I would like to redirect them to a page on a different site, the first time they visit. (I am switching domain names, and would like to introduce the new site this way) So when they go to my current domain, I would like to redirect them to the new one, and also create a cookie. Then if they try to go back to my old domain again, it will recognize the cookie, and allow them to proceed as normal. However, I am new to setting cookies, and am not sure how to do this. Or if javascript is even the right choice. Does anyone know how to do this, or have an example they can show me?

 

 

are you using a javascript framework on your old site, like jquery, mootools or prototype?

 

Actually, it is a few of sites that are being combined under one new domain. So one of the sites is Joomla, and the other is just a standard HTML based site, a third, but not as important one is using Symfony (PHP framework). It would be nice to have a redirect that could work on all 3, redirect them to the new domain, which announces the change. (only once) After the first time they are redirected, it should allow them to go to the old domain uninterrupted. I was thinking a cookie might be the right tool for the job. Any help would be appreciated.

 

 

yah, cookie is probably a good way to go.  For reading and setting a cookie, you can grab a couple of functions for that here.  And then basically on your page(s), you would have something like

 

// if cookie doesn't exist, set cookie and redirect user
if (getCookie("cookieNameHere") != "redirected") {
  // set a cookie named cookieNameHere with a value to look for, to expire in a year. 
  // it doesn't really matter what you name the cookie as long as you don't name it some other cookie name being used on your site(s).
  // it doesn't really matter what value you set it as, as long as you set it with something and look for that same something later. 
  // how long you set the cookie is up to you, based on your own timelines
  setCookie("cookieNameHere","redirected",365);

  // redirect user to new site
  location.href = "new site url here";
}

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.