Linux:使用Apache Web服务器进行重定向

时间:2020-02-23 14:39:57  来源:igfitidea点击:

这是您可以使用Apache进行的两种不同的重定向类型。
还有很多其他方法可能,例如重写规则也将在以后讨论。

将对特定域的请求重定向到严格的URL或者域。

基本上,这会将请求直接发送到目标域RootDirectory。
如果要重定向到域而不是特定的URL,请确保不要忘记尾部带有斜线的RedirectPermanent语句。

<VirtualHost *>
ServerName theitroad.com
ServerAlias optional.theitroad.com
RedirectPermanent/http://new.theitroad.com/
</VirtualHost>

将所有内容,所有可能的请求从一个旧站点重定向到一个新站点(如果愿意,也可以将一个站点重定向到另一个站点)。

假设我们有当前站点" theitroad.com",并且有一个名为" new.theitroad.com"的新站点,以下内容将基本上将" http://theitroad.com/anything"重定向到" http"的索引页://new.theitroad.com/"。

<VirtualHost *>
ServerName theitroad.com
ServerAlias optional.theitroad.com
RedirectMatch 301 ".*" http://new.theitroad.com/
</VirtualHost>