Do not change antibiotics without discussing with your veterinarian. In cats you could risk overdosing, underdosing, or causing other adverse effects.
Both cephalexin and amoxicillin are good empirical choices for a urinary tract infection (UTI) in cats.
Cephalexin at 25 mg/kg, twice per day, is an appropriate dose.
Treatment of urinary tract infections is best treated according to the results of a urine culture and sensitivity. This tells us which bacterial species is present and which antibiotic is best to treat it. However, owners often decline a urine culture due to the cost therefore in those cases an antibiotic must be selected empirically.
There are differing opinions among veterinarians as to how long to treat a urinary tract infection. If it is a simple, uncomplicated UTI, then a short course of 1-2 weeks may be sufficient. Those that are more complicated, such as causing a severe bacterial cystitis or pyelonephritis (kidney infection), warrant a longer treatment course such as 4+ weeks.
Treat the infection for the duration the veterinarian instructed. Undertreating the infection could lead to incomplete treatment, recurrent UTI, and/or antibiotic resistance. Do not stop the antibiotic just because the cat is looking better - complete the full course. For most of our first-line antibiotics such as cephalexin, long antibiotic courses are considered safe and low risk of side effects. Typically the most significant side effect with these antibiotics I see is diarrhea, as the antibiotic can also disturb the normal intestinal flora. A short course of probiotic will usually clear this up.
Your veterinarian will recommend repeating the urinalysis and urine culture after the antibiotic course is complete, to make sure the infection has cleared.
For further reading, Merck Veterinary Manual has an excellent article on Bacterial Urinary Tract Infections in small animals.