我有一个网站的3个域名。 例如example1.com,example2.com,example3.com。 我想将example2.com和example3.comredirect到example1.com。 我知道这与redirect有关,但是我在哪里放置redirect规则? 在apache或.htaccess中。 任何指针? 目前我已经设置为3个不同的虚拟主机指向同一个文件夹。 谢谢。
您可以使用.htaccess或直接在VirtualHostconfiguration中添加重写规则来完成此操作。 如果你可以编辑服务器configuration, 这里的apache文档会告诉你不要使用.htaccess。 如果你在.htaccess中这样做,当你不需要的时候,apache必须首先检查这个文件是否存在。
对于redirect本身,如果您希望http://example2.com/foo/bar/bazredirect到http://example1.com/ ,则可以使用类似于Redirect 301 / http://example1.com http://example1.com的内容 ; 如果您希望它实际上redirect到http://exmple1.com/foo/bar/baz (在主机名之后保留其余的url),则可以使用RedirectMatch 301 ^(.*)$ http://example1.com$1redirect和RedirectMatch的文档在这里
你可以用DNS来做到这一点。 在您的外部DNSlogging中,将example2.com和example3.com指向example1.com的外部IP。