Apache 将(代理)文件夹重定向到子域

发布于 2024-12-26 13:08:59 字数 443 浏览 1 评论 0原文

我需要一个重写规则,它将获取一个文件夹(动态)并将其重写到子域,它还需要对用户(代理)透明。

以下是一些示例:

示例 1

http://admin.domain.com/a/foo 

应代理至:

http://a.admin.domain.com/foo    

示例 2

http://admin.domain.com/12345/foo 

应代理至:

http://12345.admin.domain.com/foo

基本上,路径中的第一个文件夹用作子域,路径的其余部分则用作子域保持原样。

I need a rewrite rule that will take a folder (dynamic) and rewrite it to a subdomain, it also needs to be transparent to the user (proxy).

Here are some examples:

Example 1

http://admin.domain.com/a/foo 

Should proxy to:

http://a.admin.domain.com/foo    

Example 2

http://admin.domain.com/12345/foo 

Should proxy to:

http://12345.admin.domain.com/foo

Basically the first folder in the path is being used as the subdomain and the rest of the path is left as is.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

罪#恶を代价 2025-01-02 13:08:59

尝试将其添加到文档根目录中的 .htaccess 文件中:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^admin\.domain\.com$  [NC]
RewriteRule ^([^/]+)/(.*)$ http://$1.admin.domain.com/$2  [P,L]

如果要将其添加到服务器配置或虚拟主机配置中,请在正则表达式前面添加一个“/”,使其看起来像这样:^/( [^/]+)/(.*)$

Try adding this to the .htaccess file in your document root:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^admin\.domain\.com$  [NC]
RewriteRule ^([^/]+)/(.*)$ http://$1.admin.domain.com/$2  [P,L]

If you want to add this to your server config or vhost config, add a "/" in front of the regex so that it looks like this: ^/([^/]+)/(.*)$.

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