Saturday, 15 June 2013

php - splitting directory/folder into small directories with htaccess mod_rewrite -



php - splitting directory/folder into small directories with htaccess mod_rewrite -

i'm terrible mod_rewrite, , not sure if best method.

i have /image directory 20,000 or images in it. webhost says deactivate business relationship unless each directory under 2500 files.

so want alter /images/apple.jpg redirects /images/a/apple.jpg, , /images/banana.jpg redirects /images/b/banana.jpg whenever php file calls /images/apple.jpg redirect. conversely, new images created need set in right directory.

i'd code php this, image directory referenced in 736 files.

if has improve ideas - i'm open ideas.

redirecting in .htaccess new directories doesn't seem best thought need @ to the lowest degree 8 different directories (and 8 different rewrite rules) @ moment split 20000 files directories 2500 files maximum. so, tomorrow 9 directories needed, not mentioning might become hard rewrite rules select files go each directory .

i guess best alternative handle routing in php script, arrays or whatever needed.

you redirect goes /images directory php script in root, example, in turn redirects appropriate directory according parameters passed script

like this:

options +followsymlinks rewriteengine on rewritebase / rewritecond %{request_uri} !handler.php rewritecond %{request_uri} ^/images/([^\.]+)\.([\w]+)/? [nc] rewriterule .* handler.php?name=%1&ext=%2 [l]

maps silently:

http://example.com/images/filename.ext or without trailing slash.

to:

http://example.com/handler.php?name=filename&type=ext

to pass 1 parameter script, instead or name , extension, replace rewrite rule one:

rewriterule .* handler.php?%1.%2 [l]

this example. script handler can have name , keys name , type, if used.

the incoming url construction has kept rule-set work: lastly string within url must file.

for permanent , visible redirection, replace [l] [r=301,l].

php .htaccess mod-rewrite

No comments:

Post a Comment