You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "Fábio Jr." <fj...@gmail.com> on 2009/10/07 15:29:11 UTC

[users@httpd] Redirecting URLs and directory structure

Hello,

I have a server that serves static content, and most of it are images. 
These images are all stored in a directory, and there are about 4 
million images in this directory.

I believe that this storage structure is, in the medium term, unsafe and 
not dynamic, making scalability and backup virtually impossible via the 
network, mainly because the server is hosted in another country.

Thinking of a way to solve this problem, I got a chance, but that may 
not be the right solution. My suggestion is as follows:

Divide these images in directories based on the last 3 numbers of the 
file name. (The files are named in ascending order in the format 
(number).png)

Example.:

The absolute path of the file 123891.png on the server is  / 
imagens/8/91/123891.png. The file 456891.png also be in the same folder. 
However the file 123456.png will be stored in the / 
imagens/4/56/123456.png.

The structure is always based on the hundreds of file name (891), and 
the number of the hundred (8) is the parent folder, and the numbers of 
ten and unity (91) are the name of the child.

1st question: is there a way of making a request to 
http://server.foo.bar/images/123456.png, Apache will redirect or treat 
this URL for the correct path through a regular expression?

2nd question: I would like suggestions on how to better structure the 
files for better performance. Other possible solutions would be to 
create even more specific directories or the migration to a distributed 
storage service.

Thanks.

[]s
    Fábio Jr.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Redirecting URLs and directory structure

Posted by Krist van Besien <kr...@gmail.com>.
On Wed, Oct 7, 2009 at 3:29 PM, "Fábio Jr." <fj...@gmail.com> wrote:

> 1st question: is there a way of making a request to
> http://server.foo.bar/images/123456.png, Apache will redirect or treat this
> URL for the correct path through a regular expression?

You can use mod_rewrite for this, and it is entirely up to you if you
want this done with a redirect that is visible to the outside or not.

For example:

This will rewrite internally. To the outside world nothing changes:
RewriteRule /images/(.*)(.)(..)\.png     /newimages/$2/$3/$1$2$3.png

This will cause a redirect:
RewriteRule /images/(.*)(.)(..)\.png     /newimages/$2/$3/$1$2$3.png   [R]

If you do a redirect you need to worry about loops, which is why I
suggest you use a different basedir for your new images structure.

You can read about mod_rewrite here:
http://httpd.apache.org/docs/2.2/rewrite/

Study this documentation and if you have any questions left after that
feel free to ask here...

Krist


-- 
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org