perfectly legally.
Simply ask your vet to write you a prescription.
For example - Vetmedin 5mg (heart treatment) £60 for a months supply in the vet. £19 online. Metacam 180ml - months supply for large dog approx £80 in bet £23 online. These aren't exact prices but they are roughly what my mum pays out for her dogs meds.
Not all medicines will be cheaper online as there is a prescription cost of about £8 but many are. Your vets wont volunteer this information but will actually happily write you a prescription if you ask.
It isn't about your vets ripping you off, i work for a vets and they cannot buy the meds from the online suppliers, they pay more than the online price.
I don't know why that is but its ridiculous and surely has to stop because A, someone is ripping you off even if its not the vet and B, vets are going to struggle now people are getting wise to this and asking for prescriptions rather than buying the meds from their vet.
There are many companies that sell veterinary medicine online, your vet should be able to point you in the direction of a reputable company.