SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : The Server :

Previous DiscussionNext Discussion
 Regex Help

Hi everyone,

I'm trying to set up a .htaccess file to redirect any requests for MP3 files to the Coral Cache service (http://coralcdn.org).
I'm modifying some code that I found elsewhere which takes into account the Coral-specific stuff, and have only modified the last line. Here's what I have:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx
RewriteCond %{QUERY_STRING} !coral-no-serve$
RewriteRule .*\.mp3$ http://%{HTTP_HOST}.nyud.net:8090/$1 [R,L]


This has no apparent effect - requests for MP3 files are still served by my server.

Can anybody please help me with the regular expression in the last line?

Thanks,
cdrom600

Started By cdrom600 on Dec 30, 2005 at 9:59:20 AM

11 Response(s) | Reply

Earlier Replies | Replies 5 to 11 of 11 | Later Replies
Goto Page: 2 1
BachusII on Dec 30, 2005 at 4:27:22 PM (# 5)

It's not recommended to use the rewritelogs unless during testing. They fill up quick, real quick.


cdrom600 on Dec 31, 2005 at 5:31:18 PM (# 6)

All right, it seems that in addition to learning about regular expressions, I need to learn more about mod_rewrite.

I didn't know anything about rewrite logs - they seem useful, though...

Thanks for your help. I'll look into these solutions and get back to you.


cdrom600 on Dec 31, 2005 at 5:39:58 PM (# 7)

Good news!
The following code works beautifully:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx
RewriteCond %{QUERY_STRING} !coral-no-serve$
RewriteRule ^(.*\.mp3) http://%{HTTP_HOST}.nyud.net:8090/$1 [R,L]
RewriteRule ^(.*\.jpg) http://%{HTTP_HOST}.nyud.net:8090/$1 [R,L]


Two small changes:

  1. I've added a RewriteRule for JPEGs also
  2. I've removed the / from the beginning of each of the regular expressions, so that the rules will work even in subdirectories. You could also leave the / and anchor the regex to the end of the string, I think.

Thanks, guys! I have a lot of learning to do...

And Happy New Year! Be safe.
BachusII on Jan 1, 2006 at 12:03:31 AM (# 8)

^ signifies start of the string.

The slash was taken out of the parenthesis to avoid an url with a double slash at the beginning of the resulting redirect.
Because of the slash in http://%{http_host}.nyud.net:8090/$1, an url of http://server.name/path/somefile.mp3 (/path/somefile.mp3 would be what is caught by your regex) will result in http://%{http_host}.nyud.net:8090//path/somefile.mp3
That doesn't result in any problems for the server. I just don't like to build such urls.


cdrom600 on Jan 1, 2006 at 8:05:38 AM (# 9)

OK. I'll be messing with this in the next few days/weeks, and I will see what I can do, what problems may arise, etc.


Holophrastic on Jan 1, 2006 at 12:21:50 PM (# 10)

Be careful:

Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo.

"messing" is not going to be easy.


cdrom600 on Jan 1, 2006 at 2:13:31 PM (# 11)
This message has been edited.

Well, maybe not "messing", but definitely researching.


Earlier Replies | Replies 5 to 11 of 11 | Later Replies
Goto Page: 2 1

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.