Matching Digits in a mod_rewrite RewriteRule

Album Cover: New Skin for the Old Ceremony

"You told me again you preferred handsome men, but for me you would make an exception."
Leonard Cohen / Chelsea Hotel #2

Posted on January 15, 2008 1:49 PM in Web Development
Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

If you read up on the syntax of RewriteRule in Apache's mod_rewrite support, you may be led to believe that the full extent of Perl Regular Expressions is supported. After all, the following shows up verbatim in the RewriteRule documentation:

For more information about regular expressions, have a look at the perl regular expression manpage ("perldoc perlre").

However, I've found that it just isn't so. In an attempt to match a string of digits in a request and redirect to a page when the condition is met, I did something like the following:

RewriteRule ^\d\d\d /flames/ [L]

If working properly, a request to would redirect to However, it wasn't doing what I wanted to. I even tried using ^\d{3} as my pattern, but no dice.

As it turns out, it appears that mod_rewrite prefers character sets in RewriteRule patterns. Therefore, the following works as expected:

RewriteRule ^[0-9]{3} /flames/ [L]

So if you're trying to match numbers/digits in a RewriteRule, be sure to use a character set instead of the \d digit shortcut so you can avoid wasting half-an-hour of your time like I just did.


Jemima on January 25, 2008 at 5:51 AM:

Thank you! You just saved me half an hour :-)


Darwin on April 20, 2009 at 2:26 PM: wonder it wasn't working. stupid mod_rewrite.


Zen of Linux on January 30, 2010 at 2:25 PM:

Thanks a lot!


Sane on February 20, 2011 at 2:44 PM:

Worked like a charm. Thanks


followers on August 31, 2016 at 12:52 AM:

Much obliged for an awesome offer. Your article has demonstrated your diligent work and experience you have in this field. Splendid .i cherish it perusing.


instalikes on August 31, 2016 at 12:52 AM:

I discovered your this post while looking for some related data on online journal search...Its a decent post..keep posting and overhaul the data.


get followers on instagram on September 03, 2016 at 11:58 PM:

Great article with excellent idea!Thank you for such a valuable article. I really appreciate for this great information..


get likes on September 03, 2016 at 11:58 PM:

Great article with excellent idea!Thank you for such a valuable article. I really appreciate for this great information..
get followers on instagram|get likes


jrcofvvk on May 15, 2017 at 5:23 AM:
Click Here on January 30, 2018 at 2:51 AM:

Much appreciated such a great amount for this data. I need to tell you I agree on a few of the focuses you make here and others might require some further survey, however I can see your perspective.


ED treatment on February 23, 2018 at 10:15 PM:

The intellectuals of this field are making the concepts of research very necessary and effective. The production of knowledge is taking place rapidly.


landscaping on February 24, 2018 at 6:07 AM:

I think that everything has been described in systematic manner so that reader could get maximum information and learn many things.

Permalink on February 27, 2018 at 2:49 AM:

Thank you for some other informative blog. Where else could I get that type of information written in such an ideal means? I have a mission that I’m just now working on. and I have been at the look out for such information.

Permalink on February 27, 2018 at 5:09 AM:

Wonderful article. thanks for putting this together! This is obviously one great post. Thanks for the valuable information and insights you have so provided here.


You have a real ability for writing unique content. I like how you think and the way you represent your views in this article. I agree with your way of thinking. Thank you for sharing.


We are ready to serve you anytime-any where live lift your phone, then contact us, we will be ready to come to your place in Hotel, Apartment, or Home.


cozyhousetoday on June 20, 2018 at 4:07 AM:

You're so right. I'm there with you. Your blog is genuinely really worth a read if anyone comes during it.I am commenting to permit you to realize what an excellent revel in my wife’s baby enjoyed viewing your web blog. I'm fortunate I did due to the fact now I've obtained an entirely new view of this. I didn't recognize that this trouble becomes so critical and so widely wide-spread.


Post Comments

If you feel like commenting on the above item, use the form below. Your email address will be used for personal contact reasons only, and will not be shown on this website.


Email Address:



Check this box if you hate spam.