Solved

Modrewrite

Posted on 2007-12-03
7
205 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Ubuntu 14 with Apache 7 68
PHP in Apache server 20 81
RewriteRule in .htaccess file not working 8 51
DNS, website, godaddy 6 43
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

12 Experts available now in Live!

Get 1:1 Help Now