如何使用.htaccess文件将所有流量从一个域重定向到另一个域?

时间:2022-12-07 16:00:49

Say I have a subdomain xxx.yyy.com running Apache. The files are stored in /home/someone/public_html/xxx.

假设我有一个运行Apache的子域名xxx.yyy.com。这些文件存储在/ home / someone / public_html / xxx中。

What I want to do is redirect all requests to a domain name zzz.com which is using the same location for its files. (In other words, xxx.yyy.com and zzz.com are aliases for each other)

我想要做的是将所有请求重定向到域名zzz.com,该域名的文件使用相同的位置。 (换句话说,xxx.yyy.com和zzz.com是彼此的别名)

I just want people accessing zzz.com, so if someone goes to xxx.yyy.com they should be redirected to zzz.com.

我只是想让人们访问zzz.com,所以如果有人去xxx.yyy.com,他们应该被重定向到zzz.com。

Can this easily be done with a rewrite rule in an .htaccess file?

这可以通过.htaccess文件中的重写规则轻松完成吗?

1 个解决方案

#1


4  

Try

尝试

RewriteCond %{HTTP_HOST} ^xxx\.yyy\.com
RewriteRule (.*) http://zzz.com/$1 [R=permanent,QSA,L]

#1


4  

Try

尝试

RewriteCond %{HTTP_HOST} ^xxx\.yyy\.com
RewriteRule (.*) http://zzz.com/$1 [R=permanent,QSA,L]