
890 So.2d 334 (2004)
STATE of Florida, Appellant,
v.
Erik STRAZDINS, Appellee.
No. 2D03-4335.
District Court of Appeal of Florida, Second District.
December 10, 2004.
Charles J. Crist, Jr., Attorney General, Tallahassee, and Dale E. Tarpley, Assistant Attorney General, Tampa, for Appellant.
Bruce G. Howie of Piper, Ludin, Howie & Werner, P.A., St. Petersburg, for Appellee.
STRINGER, Judge.
The State challenges the sentence imposed on Strazdins for the offense of trafficking in methylenedioxymetheamphetamine (MDMA) following a no contest plea. Because it was error not to impose the three-year mandatory minimum sentence for trafficking in MDMA weighing ten grams or more but less than 200, we reverse Strazdins' sentence as to that offense and remand for further proceedings where Strazdins may have the opportunity to withdraw his plea.
The state of the law has seesawed since the trial court imposed sentence and during the pendency of this appeal. At *335 the time the trial court imposed sentence, this district had decided that a mandatory minimum sentence for the offense of trafficking in MDMA during the window period of Taylor v. State, 818 So.2d 544 (Fla. 2d DCA 2002), was unconstitutional. See Staley v. State, 860 So.2d 981 (Fla. 2d DCA 2003); Gilbert v. State, 843 So.2d 972 (Fla. 2d DCA 2003). Thus the trial court lacked the discretion to impose a mandatory minimum sentence on Strazdins. This court receded, however, from Gilbert and Staley in Wright v. State, 869 So.2d 24 (Fla. 2d DCA 2004) (en banc). In the meantime, the supreme court in Franklin v. State, 887 So.2d 1063, 1069 (Fla.2004), disapproved Taylor, thereby mooting the rationale underlying Wright. In short, a mandatory minimum sentence for trafficking in MDMA imposed under chapter 2000-320, Laws of Florida, is a legal sentence.
Appellate courts are generally required to apply the law as it exists at the time of appeal, rather than that which existed when the case was tried. Hudson v. State, 825 So.2d 460, 471 (Fla. 1st DCA 2002). When a trial court imposes a sentence that is shorter than the required mandatory minimum sentence, "the sentence is not within the limits prescribed by law and is properly viewed as an `illegal' sentence." State v. R.F., 648 So.2d 293, 294 n. 1 (Fla. 3d DCA 1995); State v. Lopez, 408 So.2d 744 (Fla. 3d DCA 1982). The State preserved the error in this appeal. See § 924.051(1)(b), (3), Fla. Stat. (2003).
The trial court had a nondiscretionary duty in this case to impose the three-year mandatory minimum sentence pursuant to section 893.135(1)(k)(2), Florida Statutes (2001). The State concedes that, on remand, Strazdins should be permitted to withdraw his plea to the charge of trafficking in MDMA. See State v. Moore, 854 So.2d 832, 834 (Fla. 5th DCA 2003).
Reversed and remanded for further proceedings.
ALTENBERND, C.J., and FULMER, J., Concur.
