如何编写代理重写

发布于 2025-01-14 03:39:57 字数 680 浏览 5 评论 0原文

我想代理网页中的所有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怼怹恏 2025-01-21 03:39:57

请尝试以下操作:

RewriteRule ^/?myapp/somepage/static/(.*) http://domain-b.com/$1 [P]

如果您只想代理 .css.js 文件(如果您有其他不应代理的文件类型),则使用限制性更强的正则表达式仅针对这些文件类型。例如。 ...静态/(.+\.(css|js))$

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))$

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文