Solved

Modrewrite

Posted on 2007-12-03
7
216 Views
Last Modified: 2010-03-04
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!!
0
Comment
Question by:admincentralmail
  • 5
  • 2
7 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 20395164
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(//, $_)));
}
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 20395179
#!/usr/bin/perl
$! = 1;
while (<>)
{
 print(join("/", split(//, $_)) . "\n"); #forgot the newline, sorry
}
0
 

Author Comment

by:admincentralmail
ID: 20395232
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 

??
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 43

Expert Comment

by:ravenpl
ID: 20395936
I haven't tested that, but should work. Test it.
0
 

Author Comment

by:admincentralmail
ID: 20397014
Do you know the code to do this:

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


Without a perl, only with RewriteCond
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 20397691
No, thats why there's RewriteMap option.
RewriteCond/Rule only matches some patterns - do not modify them.
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 125 total points
ID: 20398266
> id=12345
If You know it's always going to be 5digits, then
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} name=(\d+) [AND]
RewriteCond %{QUERY_STRING} id=(\d)(\d)(\d)(\d)(\d)
RewriteRule ^attachment.php %2/%3/%4/%5/%6/%1.thumb [L]
otherwise You need some generc code (like the one I provided)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now