Under what conditions is there a continuous bijection $f: [a, b] \to [c, d]$ such that x is rational iff f(x) is rational? For what intervals $[a, b]$ and $[c, d]$ (with $a < b$ and $c < d$) does there exist a continuous bijection $f: [a, b] \to [c, d]$ satisfying $x \in \mathbb{Q}$ if and only if $f(x) \in \mathbb{Q}$? 
If both intervals have rational endpoints, this is trivial. However, no such $f$ exists for the intervals $[0, 1]$ and $[0, \sqrt{2}]$ because a continuous bijection of a closed interval is strictly monotone, hence the endpoints of the first interval must be mapped to the endpoints of the latter. 
More specifically, if we assume that both intervals have the same number of rational endpoints (i,e, either both have rational endpoints, both have irrational endpoints, or each has one rational and one irrational endpoint), does such an $f$ always exist?
 A: Yes, it is sufficient that they have the same number of rational endpoints (and you already noted it is necessary).
If both have two rational endpoints then a linear (affine) map works.  We'll use this fact again below.
Suppose they both have one rational endpoint; without loss of generality, say that $a,c$ are rational and $b,d$ are irrational.  Let $x_0=a$ and let $x_n$ be an increasing sequence of rationals in $(a,b)$ which converges to $b$.  Likewise, let $y_0 = c$  and let $y_n$ be an increasing sequence of rationals in $(c,d)$ which converges to $d$.  Define $f$ to map $x_n$ to $y_n$ and be linear on each interval $[x_n, x_{n+1}]$.  Then $f$ maps rationals to rationals on each interval $[x_n, x_{n+1}]$, hence on all of $[a,b)$.  It is continuous and strictly increasing on $[a,b)$ by construction.  And since $x_n \to b$, $y_n \to d$, letting $f(b) = d$ gives a continuous bijection from $[a,b]$ to $[c,d]$ which maps rationals to rationals.
Suppose they both have two irrational endpoints.  Choose rationals $p \in (a,b)$, $q \in (c,d)$.   By the previous case we can find a continuous, strictly increasing map $f_1 : [a,p] \to [c,q]$ which takes rationals to rationals, and another such map $f_2 : [p,b] \to [q,c]$.  Now paste them together to get the desired map $f$.
