Apache 将旧域重定向到新域

Apache 将旧域重定向到新域,apache,.htaccess,redirect,Apache,.htaccess,Redirect,我想将主页重定向到新域中的另一个页面 www.domain.com www.newdomain.com/landing www.domain.com/es www.newdomain.com/es/landing www.domain.com/en www.newdomain.com/en/landing 与主页的其他页面不同,我可以使用规则“重定向301”重定向,但是,当我想要重定向主页时,它会变得疯狂 范例 Redirect 301 / /www.newdomain.com/landing

我想将主页重定向到新域中的另一个页面

www.domain.com www.newdomain.com/landing
www.domain.com/es www.newdomain.com/es/landing
www.domain.com/en www.newdomain.com/en/landing
与主页的其他页面不同,我可以使用规则“重定向301”重定向,但是,当我想要重定向主页时,它会变得疯狂

范例

Redirect 301 / /www.newdomain.com/landing
Redirect 301 /es /www.newdomain.com/es/landing
Redirect 301 /en /www.newdomain.com/en/landing
在home multilanguage中,重定向到www.newdomain.com/landinges


存在另一种方式?我尝试使用重写规则,但不起作用,或者我添加了错误的代码。

重定向301/
将把网站上的所有页面重定向到目标URL,下面的其余规则将不使用

您可以将
RedirectMatch
与正则表达式完全匹配:

RedirectMatch 301 ^/$ /www.newdomain.com/landing
RedirectMatch 301 ^/es/?$ /www.newdomain.com/es/landing
RedirectMatch 301 ^/en/?$ /www.newdomain.com/en/landing
或者,您可以更改规则的顺序:

Redirect 301 /es /www.newdomain.com/es/landing
Redirect 301 /en /www.newdomain.com/en/landing
Redirect 301 / /www.newdomain.com/landing

别忘了清除浏览器缓存。

工作正常!但是,我有另一个问题,但是,一些页面。示例:重定向301/page/page-x当我转到旧url时,重定向不正确(转到www.newdomain.com/page/page-x),但其他规则可以正常工作。按照我的建议使用所有的
重定向匹配
规则并发布完整的。htaccess有问题的问题解决了,情况也一样,首先,我将301重定向到/page-x,然后再重定向到/page,以另一种顺序无效。您应该使用.htaccess更新问题,并且正如我建议的那样,不要使用
重定向
。按照我的建议,只需使用重定向匹配即可。