# Split words into caracters

**URL:** <https://www.ruby-forum.com/t/split-words-into-caracters/227895>\
**Category:** NGINX\
**Created:** [April 2, 2013, 11:41am UTC](https://www.ruby-forum.com/t/split-words-into-caracters/227895 "2013-04-02T11:41:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![larry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@larry](https://www.ruby-forum.com/u/larry)\
**Post date:** [April 2, 2013, 11:41am UTC](https://www.ruby-forum.com/t/split-words-into-caracters/227895/1 "2013-04-02T11:41:27Z")

</div>

Hi !

I don’t know if it is the right way to go, and I hope to hear from you  
if it  
is not.

My concern is about the selection of a file traversing a tree. I have a  
bunch of hashed directories (dozens of millions) on different servers.  
As for performance reasons, I would like to avoid having to many  
sub-directories in the same directory.

I would rather have this scheme :  
1234/5678/90AB/CDEF/1234/5678/90AB/CDEF/myfile  
It would help proxying to the right server and so on.

Will the traverse be fast enought ? Every directory is approx 100kb  
heavy  
(really light).

But other than openresty, i didn’t see any implementation inside nginx  
to  
split any word or cookie. C is faster than lua, so it would be a good  
bet.  
Well, I think.

What is your word on it ?

Thanks !

Larry

Posted at Nginx Forum:

> **[Split words into caracters](https://forum.nginx.org/read.php?2,238015,238015#msg-238015)**
>
> Hi ! I don't know if it is the right way to go, and I hope to hear from you if it is not. My concern is about the selection of a file traversing a tree. I have a bunch of hashed directories (dozens of millions) on different servers. As for...

---

<div class="post-metadata">

**Author:** ![larry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@larry](https://www.ruby-forum.com/u/larry)\
**Post date:** [April 2, 2013, 11:47am UTC](https://www.ruby-forum.com/t/split-words-into-caracters/227895/2 "2013-04-02T11:47:18Z")

</div>

> But other than openresty, i didn’t see any implementation inside nginx to  
> split any word or cookie.

You can possibly use rewrite [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpRewriteModule) (  
[Module ngx\_http\_rewrite\_module](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html) )

There is also an example to rewrite /photos/123456 to something like  
/path/to/photos/12/1234/123456.png

rr

---

<div class="post-metadata">

**Author:** ![larry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@larry](https://www.ruby-forum.com/u/larry)\
**Post date:** [April 2, 2013, 5:39pm UTC](https://www.ruby-forum.com/t/split-words-into-caracters/227895/3 "2013-04-02T17:39:43Z")

</div>

> yeah but it works when you have multiple words.

What do you mean by multiple words?

> In my case, there is only one which is 1234567890…DEF (md5 → 32 chars)  
> m=1234567890…DEF  
> m[1] = 1  
> m[2] = 2  
> ..  
> m[32] = F

> A mere rewrite is impossible here..  
> It seems indeed,

Why not?

rewrite  
“/path/(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})(?[\w]{1})”  
/realpath/$r1/$r2/$r3/$r4/$r5/$r6/$r7/$r8/$r9/$r10/$r11/$r12/$r13/$r14/$r15/$r16/$r17/$r18/$r19/$r20/$r21/$r22/$r23/$r24/$r25/$r26/$r27/$r28/$r29/$r30/$r31/$r32;

It looks somewhat ugly because of 32 variables (aso because you need to  
use  
named ones (since $10/$11 … wouldnt work)).  
There are probably much better ways to do this, but as a proof of  
concept it  
works:

Request to [http://someserver/path/aBcdfghjklqwertyuiopas1234567890](http://someserver/path/aBcdfghjklqwertyuiopas1234567890) gets  
rewritten/translated to:

2013/04/02 18:25:37 [error] 2032#0: \*60 open()  
“/www/realpath/a/B/c/d/f/g/h/j/k/l/q/w/e/r/t/y/u/i/o/p/a/s/1/2/3/4/5/6/7/8/9/0”  
failed (2: No such file or directory), request: "GET  
/path/aBcdfghjklqwertyuiopas1234567890

(obviously error since such file doesnt exist for me)

🙂

rr

---

<div class="post-metadata">

**Author:** ![larry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@larry](https://www.ruby-forum.com/u/larry)\
**Post date:** [April 2, 2013, 7:11pm UTC](https://www.ruby-forum.com/t/split-words-into-caracters/227895/4 "2013-04-02T19:11:27Z")

</div>

You are right Reinis,

It first seemed tough to me but yeah, it works 🙂

Thanks,

Larry

Posted at Nginx Forum:

> **[Re: Split words into caracters](https://forum.nginx.org/read.php?2,238015,238034#msg-238034)**
>
> Hi ! I don't know if it is the right way to go, and I hope to hear from you if it is not. My concern is about the selection of a file traversing a tree. I have a bunch of hashed directories (dozens of millions) on different servers. As for...

---

<div class="post-metadata">

**Author:** ![larry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@larry](https://www.ruby-forum.com/u/larry)\
**Post date:** [April 2, 2013, 4:47pm UTC](https://www.ruby-forum.com/t/split-words-into-caracters/227895/5 "2013-04-02T16:47:42Z")

</div>

yeah but it works when you have multiple words.

In my case, there is only one which is 1234567890…DEF (md5 → 32  
chars)

And I would need the possibility to do

m=1234567890…DEF  
m[1] = 1  
m[2] = 2  
…  
m[32] = F

A mere rewrite is impossible here…  
It seems indeed,

Larry

Posted at Nginx Forum:

> **[Re: Split words into caracters](https://forum.nginx.org/read.php?2,238015,238029#msg-238029)**
>
> Hi ! I don't know if it is the right way to go, and I hope to hear from you if it is not. My concern is about the selection of a file traversing a tree. I have a bunch of hashed directories (dozens of millions) on different servers. As for...
