简体   繁体   English

从子域重定向到主域,而无需重写URL

[英]Redirect from subdomain to primary domain without rewriting URL

I've been searching similar solutions but none of them seems working on my server. 我一直在寻找类似的解决方案,但它们似乎都无法在我的服务器上正常工作。

What I'm trying to do is set redirect from yyy.zzz.com (subdomain) to zzz.com (primary domain) without rewriting url. 我想做的是将yyy.zzz.com (子域)重定向到zzz.com (主域), 而无需重写url。 So both yyy.zzz.com and zzz.com actually pointing at same directory and same files in it. 因此yyy.zzz.comzzz.com实际上都指向相同的目录和相同的文件。

Currently I have this .htaccess : 目前,我有这个.htaccess

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^yyy\.zzz\.com$ [NC]
RewriteRule ^(.*)$ http://zzz.com [L,NC]

Which, of course, just redirects straight on, and url actually changes. 当然,这只是直接重定向,而url实际上会改变。

Just for information, I want to set such subdomain url for CMS, so if user wants to enter CMS he does it from subdomain, while actually only $_SERVER['HTTP_HOST'] is changing. 仅供参考,我想为CMS设置此类子域url,因此,如果用户要输入CMS,则可以从子域进行操作,而实际上只有$ _SERVER ['HTTP_HOST']处于更改状态。

Any help would be appreciated. 任何帮助,将不胜感激。

You should set up a ServerAlias in your apache config. 您应该在apache配置中设置ServerAlias。 Setting yyy.zzz.com as an alias for zzz.com 将yyy.zzz.com设置为zzz.com的别名

<VirtualHost *>
ServerName zzz.com
ServerAlias yyy.zzz.com
# ...
</VirtualHost>

http://httpd.apache.org/docs/2.2/mod/core.html#serveralias http://httpd.apache.org/docs/2.2/mod/core.html#serveralias

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM