help with a mod_rewrite statement

Posted on 2006-03-24
Last Modified: 2010-03-04
first a litle explanation
i have a directory stucture of


i user mod_rewite so bob is

so to get his working i have (all letters.)
   RewriteCond %{REQUEST_URI} !^[a-zA-Z]/
   RewriteRule   ^/A([^/]+)/?(.*)    /A/A$1/$2  [L]
   RewriteCond %{REQUEST_URI} !^[a-zA-Z]/
   RewriteRule   ^/B([^/]+)/?(.*)    /B/B$1/$2  [L]
   RewriteCond %{REQUEST_URI} !^[a-zA-Z]/
   RewriteRule   ^/C([^/]+)/?(.*)    /C/C$1/$2  [L]
   RewriteCond %{REQUEST_URI} !^[a-zA-Z]/
   RewriteRule   ^/D([^/]+)/?(.*)    /D/D$1/$2  [L]

I am  thinking there must be a beteter way to do it
so i thought i would try
RewriteRule   ^/([a-zA-Z])(.*)  /$1/$1$2 [R,L]

but when i do it, mod_rewrite gets in a nasty loop
in the log file i see

thanks for any help

Question by:paries
    LVL 27

    Accepted Solution

    Why don't you keep it internal?

    RewriteEngine on
    RewriteRule   ^/(([a-zA-Z]).*)  /home/un/$2/$1 [L]

    If you need a redirectm you must add a condition to exclude an already redirected URL:

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/[a-z]/ [NC]
    RewriteRule   ^/(([a-zA-Z]).*)  /$2/$1 [R,L]

    Do you have a case-intensite platform? Otherwise /bob and /Bob would end up with in different folders. may be consider a RewriteMap.

    Author Comment


    i thought the RewriteRule   was the virtual address not the absolute.  Not sure what you mean by "internal"
    yes this is on a linux box so it is case sensitive

    LVL 27

    Expert Comment

    > was the virtual address not the absolute.

    Yes, you can use an URL-path in per-server context, too

    > Not sure what you mean by "internal"

    You used the R-Flag: [R,L]. This forces an external redirection.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
    It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now