Apache mod_rewrite rule assistance

Hello!

Hopefully, this will be simple.

I have a set of conditions requiring me to create an apache mod_rewrite rule to check for certain conditions, and if they are met, to redirect to a different port.

I need to basically rewrite any and all requests for any images (gif, jpg, png,) CSS, htm or html, to a port other than 80.

I've tried several different combinations of rewrite and redirect rules, but not having much luck.  I really need to break down and actually learn the rewrite engine.

Here's what I've tried so far.  (Please feel free to laugh!)

ReWriteCond %{SERVER_PORT} !^181$
RewriteCond %{REQUEST_URI} ^\.(gif|jpg|png)$
RewriteRule ^(.*)$ http://www.pickleberrypop.com:181/$1 [R,L]

ReWriteCond %{SERVER_PORT} !^181$
RewriteRule "^/(.*)\.(jpg|gif|png)$" "http://www.pickleberrypop.com:181/$1.$2" [L]

RedirectMatch perm ^/(.+)\.(gif|jpg|png)$ http://www.pickleberrypop.com:181/$1
eoh-jasonAsked:
Who is Participating?
 
ravenplCommented:
Sorry to inform, there's nothin to laugh at.
The first is almost there, should read(too many ^)
 RewriteCond %{SERVER_PORT} !=181
 RewriteCond %{REQUEST_URI} \.(gif|jpg|png)$
 RewriteRule (.*) http://www.pickleberrypop.com:181/$1 [R,L]

The second one is spoiled with "
 RewriteCond %{SERVER_PORT} !=181
 RewriteRule ^(.*)\.(jpg|gif|png)$ http://www.pickleberrypop.com:181/$1.$2 [R,L]

And the redirect should do as well
RedirectMatch perm /(.+)\.(gif|jpg|png)$ http://www.pickleberrypop.com:181/$1.$2
0
 
eoh-jasonAuthor Commented:
I was soo close.  Thanks for not laughing, and thanks for the help!  Works great now!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.