如何编写代理重写
我想代理网页中的所有 CSS 和 JS 文件。 例如,在网页中 http://domain-a.com/myapp/somepage/
有一些 JS/CSS。我想将所有这些 CSS/JS 代理到另一个域,比如说 http://domain-b.com
。 因此,目标是 http://domain-a.com/myapp/somepage/static/jsfiles/somejsfile.js
应代理到 http://domain-b.com /jsfiles/somejsfile.js
这意味着,/myapp/somepage/static/
之后的任何内容都应该被重写并代理到 http://domain-b.com/jsfiles/somejsfile.js
。
我已经尝试过以下方法,但它不起作用。
RewriteRule ^/myapp/somepage/static/?.*$ http://domain-b.com$0 [P]
当我打开此网址 http://domain-a.com/myapp/somepage/static/jsfiles/somejsfile.js
时,我希望从 domain-b 下载该 js 文件。 com 使用代理。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请尝试以下操作:
如果您只想代理
.css
和.js
文件(如果您有其他不应代理的文件类型),则使用限制性更强的正则表达式仅针对这些文件类型。例如。...静态/(.+\.(css|js))$
Try the following instead:
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))$