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

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

help with a mod_rewrite statement

Hello,
first a litle explanation
i have a directory stucture of

/home/un/a/
/home/un/a/ann
/home/un/b/bob
/home/un/C/
/home/un/C/Charly

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
 http://www.mydom.com/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/sam

thanks for any help

RP
0
paries
Asked:
paries
  • 2
1 Solution
 
caterham_wwwCommented:
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.
0
 
pariesAuthor Commented:
caterham_www

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

0
 
caterham_wwwCommented:
> 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.
0

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