We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41944
    • 3 Posts
    There is probably a feature in MODX I overlooked for doing this but i thought that others may find this useful.

    I had a customer who wanted to make sure that only certain people could test the new MODX site and all other visitors were sent to the old site.

    So I added this code below into the beginning of the index.php file, What it does is checks to see if the user has a cookie called 'istest', if the cookie is not set to 1 then the user is redirected to the old site home page.

    To enable
    www.mysite.com/?test=1

    Once set, you can use the MODX site as usual and test and develop the site, and visitors will be sent to the old site.

    To turn if off so that you are always redirected to the old site.
    www.mysite.com/?test=0

    There is potential to develop further, sending visitors to the right pages etc...

    Glenn

    <?php
    
    if (isset($_REQUEST['test'])) 
    {
    	$istest = $_REQUEST['test'];	
    	setcookie ("istest",$istest,  time() + ((3600 * 24) * 30) );
    } else {
    	$istest ='';
    	if(isset($_COOKIE["istest"]))
    	{
    		$istest = $_COOKIE["istest"];
    	}
    }
    
    if ($istest !== '1'){
     	//redirect if not in test mode
     	header( 'Location: htt p://www.oldsite.com/page.html' ) ;
    }
      • 10208 ☆ A M B ☆
      • 1,780 Posts
      That's very interesting. What type of "old site" are you redirecting to? Static html or some other CMS?

      I love how MODX can be installed in the root right atop a static html site and as long as you don't enable FURL's, no one knows you're developing along side it. In this case however,all visitors are still seeing the static site, and only those who know the MODX url or view from the manager can see the dev site.

      If you can provide more information about how and why you're doing this, with information about how you installed MODX (and where), it will prove quite useful to others. Thank you.
        Frogabog- MODX Websites in Portland Oregon
        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
        Having server issues? These guys have MODX Hosting perfected - SkyToaster
        • 41944
        • 3 Posts
        The client was setting up a new site, and had an existing domain name abc.com pointing to their current site xyz.com which will remain live, (Basically launching a new service)

        The new site is a clean install on a new hosting package, its using friendly urls etc so no need to worry about trying to get both sites running on the same server.

        The new site is using is using their existing domain name abc.com, and they had a requirement that it needed to be fully tested before hand and "switched on" on a Monday Morning,

        Couldn't rely on the DNS updating to the new IP address as this can take a few days, and customer could go to either site, so we switched over the domain names this week, so after a few days some of traffic was going to the new site then being redirected to the old site.

        In the mean time my clients been testing and tweaking the site as if it were live.

        On Monday (tomorrow) I will delete the few lines of code above and the site will instantly go live - no more redirection.

        I was thinking that you could also use the same code above if you had to have 2 CMS's on the same server, move the old CMS to a different folder and pass the url to that CMS perhaps convert xyz.com/products/camera > xyz.com/old/products/camera.

        Also could do the same thing above but point to a place holder page, saying "OPENING ON 1 JAN", then then it hits 1 JAN the site goes live, if you set the cookie you can access the site earlier. [ed. note: designguy last edited this post 13 years, 10 months ago.]
          • 37031
          • 93 Posts
          Perhaps another way of approaching this is to use a combination of the Site Start setting under System Settings and a Weblink resource.

          1. Create a Weblink resource and define the old site as the weblink
          2. Change the Site Start id to the newly created weblink resource id

          Then users that type in www.abc.com would get redirected to the old site while testers who type in www.abc.com/index.php?id=1 would get the new site.
            • 41944
            • 3 Posts
            See I thought there would be a way to do this within MODX, Good to know for future.

            I assume to make the website live just change the Site Start setting back to the root home page

              • 37031
              • 93 Posts
              Yuppers!