Link to home
Start Free TrialLog in
Avatar of admincentralmail
admincentralmailFlag for Spain

asked on

Modrewrite

Hi, I want change with mod rewritte all the entry request like this:

http://thumbs.domain.com/attachment.php?id=12345&name=005.jpg

By this:

http://thumbs.domain.com/1/2/3/4/5/005.thumb 

Ineed the code to do this in apache,

Thanks!!
Avatar of ravenpl
ravenpl
Flag of Poland image

I think You need to use external program for that.

RewriteEngine On
RewriteBase /
RewriteMap splitDigits prg:/path/to/splitter
RewriteCond %{QUERY_STRING} id=(\d+) [AND]
RewriteCond %{QUERY_STRING} name=(\d+)
RewriteRule ^attachment.php ${splitDigits:%1}/%2.thumb [L]

And the /path/to/splitter should be executable and should look like
#!/usr/bin/perl
$! = 1;
while (<>)
{
 print(join("/", split(//, $_)));
}
#!/usr/bin/perl
$! = 1;
while (<>)
{
 print(join("/", split(//, $_)) . "\n"); #forgot the newline, sorry
}
Avatar of admincentralmail

ASKER

I have a old php to send the thumbnails, but I want link direct to the thumbnails.

the .thumb is a .jpg

With this code I can put in the apache config and apache rewrite and convert:

http://thumbs.domain.com/attachment.php?id=12345&name=005.jpg

to this:

http://thumbs.domain.com/1/2/3/4/5/005.thumb 

??
I haven't tested that, but should work. Test it.
Do you know the code to do this:

#!/usr/bin/perl
$! = 1;
while (<>)
{
 print(join("/", split(//, $_)));
}


Without a perl, only with RewriteCond
No, thats why there's RewriteMap option.
RewriteCond/Rule only matches some patterns - do not modify them.
ASKER CERTIFIED SOLUTION
Avatar of ravenpl
ravenpl
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial