'How to write proxy rewrite
I want to proxy all the CSS and JS files in a webpage.
For example, in a webpage http://domain-a.com/myapp/somepage/ has some JS/CSS. I want to proxy all those CSS/JS to another domain let's say http://domain-b.com.
So, the goal is that http://domain-a.com/myapp/somepage/static/jsfiles/somejsfile.js should be proxied to http://domain-b.com/jsfiles/somejsfile.js
That means, whatever comes after /myapp/somepage/static/, should be rewritten and proxied to http://domain-b.com/jsfiles/somejsfile.js.
I have tried the following but it does not work.
RewriteRule ^/myapp/somepage/static/?.*$ http://domain-b.com$0 [P]
When I open this url http://domain-a.com/myapp/somepage/static/jsfiles/somejsfile.js then I expect that js file to be downloaded from domain-b.com using proxy.
Solution 1:[1]
Try the following instead:
RewriteRule ^/?myapp/somepage/static/(.*) http://domain-b.com/$1 [P]
If you only want to proxy .css and .js files (if you have other file types that should not be proxied) then use a more restrictive regex to target just those file types. eg. ...static/(.+\.(css|js))$
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MrWhite |
