Your doctor will ask you about your symptoms. He or she will examine you and may take X-rays or other imaging tests, such as a computed tomography (CT) scan or a magnetic resonance imaging (MRI) scan, to look for problems in your sacroiliac joints or any other joints that are painful or stiff. Your doctor also may order a blood test to look for a gene called HLA-B27. This gene is found more commonly in people with ankylosing spondylitis than in other people. However, having the HLA-B27 gene does not mean you have or will develop ankylosing spondylitis. Your doctor will diagnose the condition based on a combination of symptoms, physical examination, blood tests and imaging tests.