URL Rewriting - ProxyHTMLURLMap


I am trying to write a virtual host rule (Apache) to rewrite URLs contained within html.  What I am trying to do, is to automaticaly direct URLs for directories containing static files - eg. www.mysite.com/css/ to a domain specificaly set up to server static content (eg. static.mysite.com/css/

I have tried version permutations of:

<Location /css/>
 ProxyHTMLURLMap /css/ http://static.mysite.co.uk/css/

But it doesn't work.  The tags being serviced are eg: /css/main.css which I would like to be rewritten to static.mysite.co.uk/css/main.css before being served up by Apace.

My reason for doing this is to get static content served by nginx and from a cookie free domain, but without too much messing around with the development environment (cakephp)

Hope you can help..

Who is Participating?
ahoffmannConnect With a Mentor Commented:
# either use redirect
RedirectMatch /css/(.*)$ http://static.mysite.co.uk/css/$1

# or use Rewrite
RewriteCond %{REQUEST_URI} !^/*css/
RewriteRule /css/(.*)$ http://static.mysite.co.uk/css/$1
richp10Author Commented:
Many thanks.  

The second solution 404'd on me.  I think the first one led me to an acceptable solution.  I think the redirectmatch provides a  temporary redirection, I also tried:  

Redirect permanent /css/ http://static.mysite.co.uk/css/ 

I think this is working.

What I was trying to do with ProxyHTMLURLmap was re-write urls embedded within the returned html - so the actual requests from the browser went direct to the static.mysite.. domain.  I think the only cost of the redirect is a single request which returns a 304, and after that requests will go direct to the static domain...  

If there is anyone lurking that thinks there is a better way of doing this (or thinks I have my reasoning wrong) please speak up quick - or I am minded to accept the proposed solution as close enough..

Thanks again aHoffman

> .. was re-write urls embedded within the returned html
for that you need a sophisticated output filter, you better fix your web site for that ;-)
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.