[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

help with a mod_rewrite statement

first a litle explanation
i have a directory stucture of


i user mod_rewite so bob is http://www.mydom.com/bob

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

  • 2
1 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.
pariesAuthor Commented:

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

> 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now