Spray the rug with natures miracle available at pets stores.
Go to MyPetPeed.com on the internet . I bought some of this amazing miracle and it works like a charm. Quite expensive but you get what you pay for and it's well worth it. I also used it on clothing stains as well. You just spray it on til pretty wet and walk away. NO SCRUBBING! It took hot pink stains off of a new blouse when I thought the blouse was ruined!
Wash or saturate the rug with white vinegar.
There is some stuff you can get at any Menards called ODOBAN.. works great
Get rid of the rug - honestly. Natures Miracle works great but it doesn't remove the smell 100% - the dog can still smell it. Remember even if we can't smell it the dog probably can. Scents etc. don't make it go away, just masks it. I would spend my time & $ on training the dog or making changes so the dog doesn't do that anymore. Keep in a crate when not supervised, more potty time outside (supervised so you know they've gone before coming inside) etc. I do these things with my dogs - as puppies and as seniors. Many times is training us not them :) LOL. (I have taught obedience/dog training and working with TTouch - all positive reinforcement not punishment- if you have questions let me know!)
Shampoo the rug throughly then spray with Natures Miracle on a regular basis, dogs don't like the smell of it. By the way, this product is far less expensive if you order on line thru Pet Smart verses buying it in the store.
Having spent many decades and over half my life with this issue, seriously, scrap the rug, replace with replacable others. And thinkabout it, no chemical will teach an old dog new tricks. Nothing will ever get it all out or teach him to hold it in, and at best, find a new spot . But for now, any of the enzyme products. then lots and lots of fresh air and sunshine will help.
Can you replace the rug? If you can, do that! If not, use vinegar. Completely saturate the entire area with vinegar. Let it soak for a bit and then suck it up with a carpet cleaner or wet/dry vac. Once it is completely dry, check for the smell again. If it's still there, chances are you didn't get the entire area or that it has soaked through the carpet and pad and into the floor boards.
I love my dog so much but it constantly did the things that irked me most. It would chew on things that it shouldn’t or jump up and down out of the blue. Whenever I put on the leash, it would pull on it. Whenever it was out of the house, it would continue digging on the ground - I wish I could tell what it was looking for down there. All the things it did left me feeling depressed as if I failed it monumentally.
But since I discovered Brain Training for Dogs and applied the system offered, it now behaves the way a beautiful dog I always expect of.