You can spray ivory soap or bitter apply spray to make it taste bad. Then give him/her an item that he/she can chew on like chew toys, grass mats, hay, alfalfa cubes, and wooden chew sticks.
Change rug/flooring a few things will trigger my own bunnies to chew and a few rugs would never work with them. You can try changing the rug to something else and see if your bunny will have a go on the rug.
You can also try giving your bunny chewing toys and place them on the rug. That’s how I did placing chewing toys where they often chew and they at least got a bit kinder to the wooded furniture in the house.
Don't spray anything near bunnies. Keep them in a LARGE safe enclosure with flooring they don't chew. Only let them out when you can supervise with 100% attention and stop them (by making a noise they don't like) EVERY time they eat carpet. Consistency is very important. If they only dig or chew in a corner you can try putting a ceramic tile there. You are right to worry about this, eating carpet is very dangerous. Of course, also give them plenty of toys they are allowed to chew. Good luck!