OK, but this was under Irish tax rules, which are the same for everyone. The Commission's argument is effectively that no-one else was doing it (which seems a bit odd) so it amounts to state aid. This is fairly wonky reasoning (and even Steely Neelie had an opinion piece in the Guardian that she thought it was a step too far).
The "non-resident company" tax arrangements that Apple and others use (non-resident companies) is being phased out - the end date is 2020 and no new companies of this type can be registered. This was the really problematic part of the whole affair, because the companies incorporated in Ireland as non-tax-resident. These rules have been in place for a long time - Apple started using them in the late 70's/early 80's.
The gap is easy to understand - Ireland have "territorial" taxation, so profits made by subsidiaries of Irish registered companies abroad are not liable for tax (unlike, say, the US). The rest of the EU have a common market for goods and services, so the profits are not taxable there, either, because the company is registered in Ireland. It seems like there are a number of easy fixes (the Irish took the one available to them in 2013, as mentioned above).