Force Lower-Case URLs with mod_rewrite

You may find yourself in a situation at some point where you need to ensure that all access to your site is done using lower-case only. This may be because of SEO (avoiding duplicate content), or perhaps you want to ensure that you can seamlessly move between case-sensitive/insensitive operating systems. If you are running a standard LAMP stack, you’re in luck. Apache’s mod_rewrite can be used to 301-redirect all incoming requests to their lower-case counterparts with just a few configuration directives.

10. Don’t be Case Sensitive
Since URLs can accept both uppercase and lowercase characters, don’t ever, ever allow any uppercase letters in your structure. If you have them now, 301 them to all-lowercase versions to help avoid confusion. If you have a lot of type-in traffic, you might even consider a 301 rule that sends any incorrect capitalization permutation to its rightful home.

It doesn’t require much to rewrite URLs to lower-case, and the necessary configuration directives can be placed in either a virtualhost or .htaccess file. First, the RewriteEngine is enabled, and a custom RewriteMap called ‘lc’ is defined using the internal ‘tolower’ map. Next, a RewriteCond rule is used so that only URLs containing upper-case characters are rewritten. Finally, the actual RewriteRule is defined using the ‘lc’ RewriteMap that we just created to transform the captured URL to lower-case before 301-redirecting the user.

RewriteEngine On
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]

The following is the output from the RewriteLog that shows the processing for a request to /INDEX.PHP. Note that only a single upper-case letter needs to be present for the rewrite rule to be triggered. The log output clearly shows the rewrite rule being applied, the RewriteMap being referenced, and the 301 redirect taking place. The subsequent request for /index.php is also shown, where the rewrite condition does not match and the request is passed through.

init rewrite engine with requested uri /INDEX.PHP
applying pattern '(.*)' to uri '/INDEX.PHP'
RewriteCond: input='/INDEX.PHP' pattern='[A-Z]' => matched
map lookup OK: map=lc key=/index.php -> val=/index.php
rewrite '/INDEX.PHP' -> '/index.php'
explicitly forcing redirect with http://test/index.php
escaping http://test/index.php for redirect
redirect to http://test/index.php [REDIRECT/301]
init rewrite engine with requested uri /index.php
applying pattern '(.*)' to uri '/index.php'
RewriteCond: input='/index.php' pattern='[A-Z]' => not-matched
pass through /index.php
Chris Abernethy
PHP Wrangler, MySQL DBA, Linux SysAdmin and all around computer guy, developing LAMP applications since Slackware came on 10 floppy disks.

91 Comments on "Force Lower-Case URLs with mod_rewrite"

  1. Ratnesh says:

    Hi there,
    I am having problem with the above code its not working on local servers.(WAMP)
    The error it gives is internal server error.
    where should I place this code
    I thinks in the

    RewriteEngine On
    RewriteMap lc int:tolower
    RewriteCond %{REQUEST_URI} [A-Z]
    RewriteRule (.*) ${lc:$1} [R=301,L]

    Please help me out.

  2. Steve says:

    I’m getting the internal server error as well. I suspect that it has to do with the configuration of the servers. Specifically: “Due to the way in which our server environments are setup you may not use php_value arguments in a .htaccess file.”

  3. Hello, its fastidious article on the topic of media print, we all be aware of media is a wonderful source of facts.

  4. Kenan says:

    @Ratnesh for localhost you need to open rewrite extension.

    Also i did it for my web site but nothing changed . It shows again uppercase.

  5. Reflexologías aplicadas al quiromasaje Personas que quieran ampliar
    y enriquecer su desarrollo personal y aplicar el masaje en su entorno familiar.
    MASAJE TAILANDES TRADICIONAL sesenta ´ Información y
    cita previa al 616 55 99 veinticinco Historia del masaje..

  6. Actually when someone doesn’t understand afterward its up to other visitors that they will help, so here it occurs.

  7. Usually I don’t read post on blogs, however I would like to say that this write-up very forced
    me to try and do so! Your writing taste has been amazed me.
    Thanks, very great article.

  8. Josette says:

    Excellent post. I used to be checking continuously this weblog
    and I’m impressed! Very useful information specially the ultimate phase :)
    I handle such information much. I was looking for this certain info for a very lengthy time.
    Thank you and good luck.

  9. I am really loving the theme/design of your web
    site. Do you ever run into any web browser compatibility issues?

    A few of my blog readers have complained about my website not working correctly in Explorer but looks great in Safari.
    Do you have any advice to help fix this problem?

  10. This is the right webpage for anybody who wishes to understand this topic.
    You understand so much its almost tough to argue with you (not that
    I actually would want to…HaHa). You definitely put a new spin on a topic which has been written about for many years.
    Great stuff, just excellent!

  11. Reto90 says:

    Hi there Dear, are you actually visiting this web page daily, if
    so then you will without doubt take pleasant knowledge.

  12. First of all I want to say terrific blog!

    I had a quick question in which I’d like to ask if you don’t mind.

    I was interested to know how you center yourself and clear your mind before writing.
    I’ve had trouble clearing my mind in getting my ideas
    out there. I do take pleasure in writing however it just seems like the first
    10 to 15 minutes are usually wasted just trying to figure
    out how to begin. Any ideas or tips? Many thanks!

  13. Very good blog post. I absolutely appreciate this website.
    Keep writing!

  14. It is in reality a nice and helpful piece of info.

    I’m satisfied that you just shared this useful info with us.

    Please stay us informed like this. Thank you for sharing.

  15. It’s really a cool and helpful piece of info. I’m glad that you simply shared this helpful information with us.
    Please stay us up to date like this. Thank you for sharing.

  16. Ytb is the only mlm firm that offers you without spending a dime,
    . a long time upfront as a result of data about it was gathered through
    DARPA’s secret time travel program unlocks a number of
    of the extra enigmatic details within the Mr. Basiago has publicly answered
    questions about this corroborating photographic proof of his time travel experiences within the secret U.S.
    government program during which time travel was achieved.

  17. Iphone four GEVEY Sim Adapter FAQ:
    If your Iphone 4 has customized firmware, the GEVEY Sim adapter will not get the job done.
    You must restore your Iphone 4 to the original Apple iphone four

  18. says:

    I wanted to thank yyou for this great read!! I definitely loved every
    bit of it. I have you book marked to look at new things you post…

  19. web page says:

    Attractive portion of content. I simply stumbled upon your weblog and in accession capital to assert that I get actually loved account your blog posts.
    Any way I will be subscribing to your feeds and even I success you get
    entry to constantly fast.

  20. agen tangkas says:

    I am genuinely glad to glance at this weblog posts which carries lots of valuable facts,
    thanks for providing such data.

  21. I read this post completely on tthe topic of the resemblance of most recent and preceding technologies,
    it’s amazing article.

  22. Why do not we just examples of the Prophet Muhammad, rather than looking for
    money that is not kosher as stealing, robbing, and corruption. Of these converts, the most qualified
    became “sheikhs”, as they were reverently called,
    and in various cities began study circles, gaining converts by the dozens, especially in the Midwest.
    The UK is served by two channel on the SKY network.

  23. automatem says:

    wonderful put up, very informative. I wonder why the other specialists of
    this sector don’t understand this. You should continue your writing.

    I am confident, you have a great readers’ base already!

  24. Have you ever considered writing an e-book oor guest authoring onn other blogs?

    I have a blog centered on the same information you discuss aand would really like
    tto have you suare some stories/information. I know my audience would value your work.
    If you’re even remotely interested, feel free to send me an e mail.

  25. says:

    The remaining cards (56 cards) are referred to as the Minor Arcana.
    Some people find this particularly uncomfortable due their off-putting associations.

    Horoscope is an established branch of science that takes into account planetary positions, person’s zodiac sign and date of

  26. Besides teaching at Harvard, this man does consulting for
    Microsoft, the NFL, the New York Times and Universal Music on ‘preventing and detecting online fraud.
    The best way to find a best Indian restaurant in your town is to
    read the reviews and check the ratings of the restaurant online.
    Some major institutes providing this degree includes Ashford University, Columbia
    Southern University, South University, Beckfield College, Kaplan University, Pittsburgh Technical Institute, University of Phoenix, Vancouver Career college , Strayer University and YTI Career Institute.

  27. Hello my family member! I want to say that this article is
    amazing, great written and include approximately all vital infos.
    I would like to see extra posts like this .

  28. Great post. I was checking constantly this blog and I’m impressed!

    Extremely useful information particularly the last part :) I
    care for such information a lot. I was seeking this particular info
    for a very long time. Thank you and good luck.

  29. Dessert ecosystem animals- Animals found in desert
    regions will be nocturnal carnivores. In coping with the
    loss of your pet, guilt can be one of the strongest emotions you
    experience. What follows is an overview of several of the most rare breeds of Persian cats:
    The fantastic white is most likely the most preferred wide variety of this unique

  30. Stephaine says:

    When someoe writes an paragraph he/she keepps the plan of a
    user in his/her brain that how a user can know it.

    So that’s why this article iis perfect. Thanks!

  31. Nice post. I learn something totally new and challenging on websites I stumbleupon every day.
    It’s always helpful to read articles from other authors and practice a
    little something from their websites.

  32. Ingeborg says:

    I used to be suggested this website by means of my cousin. I am no longer positive
    whether or not this put up is written by him as no one else know such targeted approximately my difficulty.
    You are wonderful! Thanks!

  33. Davida says:

    Hello just wanted to give you a quick heads up. The words in yokur
    post seem to be running off the screen in Internet explorer.
    I’m not sude iff thiis is a formatting issue or something to do with internet browser compatibility but I
    figured I’d post to let you know. The layout look great
    though! Hope you gget the problem fixed soon. Cheers

  34. says:

    Horny goat weed: When you’re developing a hard time in dealing with dull sex-life, than the herb will probably
    be your perfect option. Montys_Mom: It was a tough couple years
    when I had to live with my mother in-law. What’s the
    aim of losing two pounds in a week when you’ve
    got 120 to go.

  35. games says:

    This article will help the internet users for creating new webpage or
    even a blog from start to end.

  36. Nice weblog here! Additionally your website so much up very fast!
    What host are you the usage of? Can I am getting your affiliate hyperlink
    for your host? I wish my website loaded up as fast as yours lol

  37. fluconazole says:

    If you want to obtain much from this paragraph then you have
    to apply these strategies to your won weblog.

  38. We are going to choose the ten top recipe thought submissions and will send 3 samples of the chosen product to the successful foodies.

  39. Pirate Bay says:

    There it absolutely was revealed that the PSP’s future may look very gloomy out.

    The uncovering of dried fruits, grains and dried, salt preserved fish and meat are traced time for over seven thousand years to these first ancient
    civilizations. Just because school rates aren’t advertised, that doesn’t mean that they
    aren’t available.

  40. And it is acquired the very powerful voice of Francisco Alves.

  41. 隨身硬碟 says:


  42. whoah this weblog is fantastic i love studying your articles.
    Keep up the great work! You know, a lot of individuals are hunting round for this info, you
    can help them greatly.

  43. It’s going to be finish of mine day, however before finish I am
    reading this impressive article to improve my experience.

  44. This paragraph is truly a fastidious one it assists new internet viewers, who
    are wishing in favor of blogging.

  45. I do trust all the concepts you have introduced for your post.

  46. ipsec says:

    It’s awesome to pay a quick visit this web page and reading the views of
    all friends concerning this article, while I am also keen of getting experience.

  47. Great site you’ve got here.. It’s hard to find high-quality writing like yours these days.

    I honestly appreciate individuals like you! Take care!!

  48. tricks says:

    I just like the valuable info you supply for your articles.
    I’ll bookmark your weblog and test again right here regularly.
    I am relatively sure I’ll be told a lot of new stuff proper here!
    Best of luck for the following!

  49. Susan Ormond says:

    Excellent article as always.

  50. It’s in fact very complex in this active life to listen news on Television, so I just use world wide web for that reason, and
    obtain the most up-to-date information.

  51. Zahra says:

    excellent as always. book marked and will come back for more insight.

  52. Excellent beat ! I would like to apprentice whilst you amend your website, how could i subscribe for a blog website?
    The account aided me a applicable deal. I have been a little bit acquainted of
    this your broadcast provided bright clear idea

  53. I know this web page presents quality depending content and extra information, is there
    any other site which offers such things in quality?

  54. Why must I worry about your organizationis host?

  55. Hello Dear, are you really visiting this web page regularly, if so afterward you will definitely get fastidious knowledge.

  56. I think the admin of this website is in fact working hard
    in support of his web site, since here every stuff is quality based information.

  57. It the le mieux le temps pour faire quelques plans pour l’avenir et cela
    l’is le temps pour être heureux. I’ve lisent ce poste et si je pourrais je wish to vous suggèrent les choses intéressantes few ou advice.

    Perhaps vous can écrivez des articles suivants
    faisant allusion à cet article. Je veux to lu even plus les choses de cela !

  58. kanthal says:

    Can I simply just say what a comfort to uncover somebody who actually knows what they’re discussing on the net.
    You actually realize how to bring a problem to
    light and make it important. A lot more people have to
    check this out and understand this side of your story. It’s surprising you’re not more popular
    since you most certainly possess the gift.

  59. Thanks on your marvelous posting! I actually enjoyed reading
    it, you happen to be a great author. I will ensure that I bookmark your blog and definitely will come back sometime soon. I want to encourage
    you to definitely continue your great posts, have a nice weekend!

  60. backpacker says:

    Hello to all, the contents existing at this site are actually remarkable for people experience, well,
    keep up the good work fellows.

  61. It runs on the latest technology and its noise level is
    quiet bearable and will not cause any disturbance to anybody.
    Its 1,210-watt output is good enough to handle most commercial needs, and the dimensions of this handy coffeemaker are about 11.
    Embarrassment of the traditional consumption of kitchen appliances.

    Cooking can take a significant portion out of your monthly budget,
    but so, too, can the appliances in your kitchen. Even your children can use
    food processors very conveniently.

  62. April says:

    Choices include moisturizers, face and physique tightening merchandise, pure breast implants, face lotions, cellulite creams, spider veins.
    Modern cosmetic plastic surgery can provide you with an innovative new
    look. However, it is very important be aware that the
    gain of fat is not capable of be sequestered within confident areas from the body and definitely will also
    come in plentiful the areas with the body as well.

  63. Anonymous says:

    Uh…the comments are almost all spam. Do you monitor your website at all?

    The solution doesn’t work. I think the int:tolower piece needs to be configured in httpd.conf first, and most servers don’t have this by default.

  64. situs judi says:

    fantastic points altogether, you simply won a new reader.
    What could you suggest about your publish that you just
    made a few days ago? Any sure?

  65. You ought to take part in a contest for one of the highest quality blogs on the internet.
    I am going to recommend this blog!

  66. frustrated says:

    Dpa is ANN’s unique syndication associate and as such, distributes news and features originating from ANN.

  67. It be­came known as CamelCase, and its resonance would later be seen in scores of Internet brands such as AltaVista, MySpace, and YouTube.

  68. randki says:

    Hello everyone, it’s my first pay a visit at this website, and paragraph is really fruitful in support of me, keep up posting these types
    of posts.

  69. sam says:

    You ought to take part in a contest for one of the highest quality blogs on the internet.
    I am going to recommend this blog!

  70. Assalamualaikum. Setelah saya mampir dan melihat-lihat produk yang
    dijual di toko online anda, saya sangatlah tertarik.
    Bisakah saya menjadi reseller atau dropship. Salam kenal dan sukses selalu.

  71. colusion says:

    Helpful info. Fortunate me I discovered your website by accident, and I’m stunned why this coincidence did not
    happened earlier! I bookmarked it.

  72. Thanks, this site is very valuable.|

  73. Keep up the remarkable work !! Lovin’ it!|

  74. leaf blower says:

    Useful information. Lucky me I discovered your web site by chance, and I’m stunned why
    this accident didn’t took place in advance! I bookmarked it.

  75. Keep up the good job and generating the crowd!

  76. Wow, gorgeous site. Thnx ..

  77. Fletcher says:

    I am genuinely grateful to the holder of this site who has shared this
    enormous paragraph at here.

  78. よくテレビで流れる、みんなが知っているキャッシングの金融会社はほとんどがスピード審査を売りにしていて、最短で受けられる即日キャッシングに対応することも可能です。審査に必要な時間も早いところだと最も短くて30分前後です。無利息サービスの特典は、それぞれのキャッシング会社で違うので、ネットをうまく利用して様々なサイトを比較してみていくことで、自分に向いている便利なところを探すことができるでしょう。

  79. こんにちわ


  80. gadgets says:

    Very good blog! Do you have any helpful hints for aspiring writers?
    I’m planning to start my own site soon but I’m a little lost on everything.
    Would you propose starting with a free platform like WordPress or go for
    a paid option? There are so many choices out there that I’m totally overwhelmed ..
    Any recommendations? Thank you!

  81. とーっても共感出来る内容だったので、ちょっとメッセージつけちゃいますね。



  82. 消費者金融の即日借り入れは、とても使いやすいキャッシングです。最近は、消費者金融を気軽に活用する人が増加しています。少額だけキャッシングする場合、利息も少額ですむのが支持を集める理由です。

  83. 家庭で本格的なレーザー脱毛ができます。もっとも効果的な脱毛器は、こちら>>

  84. 俺も覚えのある節がありますね。正しく情報を知っているのと知らないのとでは、それが引き起こす結果は極端に異なってくるとは認識していたはずでしたが、それが航空チケットについても当てはまるとは認知していませんでしたね。安上りな航空切符について、一括で比べるサイトをかねてから利用していたのですが、実はまともに買った方が安くなると分かった時は茫然自失でした。こういうことは、なんで誰一人伝えてくれないのでしょうね~。

  85. b-up says:


  86. idm download says:

    It’s amazing to pay a visit this site and reading the views of all friends concerning this article, while I am also zealous of getting experience.

  87. At this time I am ready to do my breakfast, when having my breakfast coming again to
    read additional news.

  88. 千葉県のイラストレーター求人について知って読取る!お役立ち敷地です。

  89. I blog often and I really appreciate your content. The article has really peaked my interest.
    I’m going to book mark your website and keep checking for new information about once per week.
    I subscribed to your Feed too.

  90. 堤さやか says:

    Hi there to all, it’s truly a fastidious for
    me to go to see this site, it consists of valuable Information.

  91. Aw, this was an incredibly good post. Finding the
    time and actual effort to create a very good article… but what
    can I say… I procrastinate a whole lot and don’t manage to get nearly anything done.

Got something to say? Go for it!