rig problem: knees bend sideways instead of forward and backward
You need to set the IK Pole Target and pole angle. Follow JerryNo's answers How to IK rig legs and How to Set/Calculate pole angle of IK constraint