Solved

Modrewrite

Posted on 2007-12-03
7
224 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

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.

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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