使用.htaccess重写子域名(rewrite subdomain using .htaccess)

编程入门 行业动态 更新时间:2024-10-24 22:31:00
使用.htaccess重写子域名(rewrite subdomain using .htaccess)

我的主域是subdomain.domain.tld ,我想将所有从subdomain1.domain.tld到第一个的流量重写。 这意味着如果某人访问了subdomain1.domain.tld/whatever.php ,他实际上访问了subdomain.domain.tld/whatever.php ,但是他仍然在浏览器的导航栏中显示了subdomain1 。

我做了一些研究,但是我找不到太有希望的东西。

My main domain is subdomain.domain.tld, and I want to rewrite all the traffic from subdomain1.domain.tld to the first one. Meaning if someone accesses subdomain1.domain.tld/whatever.php, he actually accesses subdomain.domain.tld/whatever.php, however, he's still shown subdomain1 in the browser's navigation bar.

I did some research, but I couldn't find something too promising.

最满意答案

你不需要为此重写,事实上在不同的主机之间不可能进行内部重写......

假设两个“子域名”(实际上是主机名称)由同一个http服务器提供服务,您可以简单地为两个主机配置相同的DocumentRoot 。 这样他们就可以提供完全相同的文件系统,这显然意味着将调用相同的脚本。

如果您只是为您的虚拟主机使用ServerAlias命令,那么您可能会更加简单。 这显然是唯一可能的,如果你不需要两个主机单独的配置。

只要看看apache http服务器的文档。 这是解释和提供很好的例子: https : //httpd.apache.org/docs/2.4/vhosts/examples.html


如果这两个主机不是由同一个http服务器提供服务,那么您可以使用内部代理设置: subdomain1.domain.tld充当subdomain1.domain.tld的前端代理,因此它只是中继所有传入请求,并且还传出响应。 这很容易通过apaches代理模块提供的ProxyPass和ProxyPassReverse规则的组合完成: https ://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypassreverse

如果两个http服务器在不同的IP地址或甚至完全独立的系统上运行,甚至可以使用此设置。

You don't need rewriting for this, in fact internal rewriting is not possible between separate hosts...

Assuming that both "subdomains" (those are actually hostnames) are served by the same http server you can simply configure the same DocumentRoot for both hosts. That way they serve exactly the same file system which obviously means that the same scripts will be called.

Maybe you can get away even more simple if you just use the ServerAlias command for your virtual host. This obviously is only possible if you do not need separate configurations for both hosts.

Just take a look into the documentation of the apache http server. This is explained and good examples are offered: https://httpd.apache.org/docs/2.4/vhosts/examples.html


In case those two hosts are not served by the same http server you could use an internal proxy setup: subdomain1.domain.tld acts as a front end proxy for subdomain.domain.tld, so it just relays all incoming requests and also the outgoing responses. That is easily done with a combination of the ProxyPass and the ProxyPassReverse rules offered by apaches proxy module: https://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypassreverse

This setup can even be used if the two http servers operate on different IP addresses or even completely separate systems.

更多推荐

本文发布于:2023-07-05 07:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034873.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   域名   htaccess   rewrite   subdomain

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!