I just started experiencing the same symptoms a couple of weeks ago. You have Ankylosing Spondylitis. The good news is that most of the inflammation is caused by food allergies, and that you can become pain free by going on a No Starch Diet and a few other modifications.
Definitely go see your physician but here is my story and how I stopped the back and rib pain:
The key components that worked for me are:
1. Sleeping and resting on a layer of Memory Foam over a hard surface.
2. A strict No Starch Diet (a low starch diet did not work for me).
3. Stopping all medications like Advil and Tylenol that test starch positive.
4. Heat Packs, such as ThermaCare HeatWraps, to relieve the pain.
I initially started taking Tylenol and Advil, which would relieve the pain for several hours, but worsen the flare after the effects wore off. Same for Prednisone 5 mg daily, which I started myself on the third day after I started waking up in the middle of the night with excruciating low back pain and bilateral rib pain, with severe crippling upper and lower back pain during the day that was an 8 or 9 on a pain scale of 10.
As some of you have found, prednisone douses the inflammation almost miraculously. I felt so good the next day I went to see a movie with minimal discomfort. Only problem is that it only lasted 25-26 hours, then it seemed to WORSEN MY SYMPTOMS. I took prednisone for 6 days so I could still continue to work. Then stopped prednisone and all other meds after I found they all tested positive for starch, using the iodine test.
I cold-turkey'ed all the other body-care products that had starch. I stopped using my Shesiedo skin care face moisturizing products, all makeup, and stopped using my shampoo, conditioner, and body lotion. These all sadly tested starch positive. This may not really be necessary, but it is what I did to completely clear my system of starch.
My pain decreased by 40% off prednisone, Advil, and Tylenol, and I was able to work a full day using only wearable heat pads to my upper and low back.
But the kicker was when I switched from a low-starch diet to a completely pure No Starch Diet (NSD). The former was through ignorance; didn't start iodine testing for a couple of weeks.
4 hours after starting a NSD, I was completely pain free for the first time in 12 days!!! It really works. Please do try it. The incredibly fast response may have been because I had been off all medications and all body-care products since the day before.
Fasting will likely work, but I hate feeling hungry. So what I did is eat a pure meat and fish diet that my husband cooked using only using salt, and sometimes grapeseed oil.
The last 6 days since I first became pain free have been pure bliss. My pain has been minimal, from 0 to 1. And only worsens to a pain scale of 2 out of 10 when I eat something my body is allergic to, which for me I have found so far to be eggs, blueberry, crunchy melon, and figs. But the pain quickly resolves in less than 3 hours, as long as I go back to eating just my safe foods, which I now just use my body's response to test.
Foods that seem to douse the inflammation, so that my back feels almost completely normal, are Hershey's 1.55 oz. Milk Chocolate bars (they are gluten free), cantaloupe, and Trader Joe's organic Plain Yogurt. Not sure if it is just one or if all 3 have that effect; will try to parse it out over the next few days.
The other significant component to my healing has been lying down on a firm surface covered by a layer of 1-1/2 inch memory foam (only $27 for a full size at Wal-Mart). For me, that hard surface has been my hard, armless, cushion-less couch. As soon as I started sleeping on this, it was like sleeping in heaven. No more waking up 4 hours later with excruciating low back pain and scary bilateral rib pain.
Resting on this is truly healing for me, I believe not just from the cushioning but also from the warmth the memory foam provides. Whenever I have back pain, I lie down and rest. The pain almost immediately goes away, and when I get up 1/2 hour or 1 hour later, it is minimal or completely gone. Better than Tylenol or Advil--the same effect without the afterward worsening of the inflammatory symptoms.
As an interim, until you can get a good Tempurpedic or Sleep Number mattress, I would suggest removing the cushions on your sofa, applying two 1-1/2 inch layers of Memory Foam, and sleeping on that. Or simply using two layers of Memory Foam on the floor. You will immediately know if this works for you.
Also, I've made up Memory Foam cushions for my carseat and work chairs, which helps alleviate the pain by a huge factor and allows me to function almost normally. Before doing this, and getting the flare under control, driving that 1 hour to work and then back was sheer agony.