首页 > 解决方案 > htaccess 将特定语言的域重定向到新域

问题描述

我有两个旧域http://example1.com英语)和http://example2.com法语),并希望它们重定向到我的新域,例如:

http://example1.com => http://newdomain.com/en/

http://example2.com => http://newdomain.com/fr/

此外,我想确保永久链接在重定向后也保持不变。

例如http://example1.com/test.html => http://newdomain.com/en/test.html

我的代码:

下面的代码无法维护永久链接,我也不确定如何在检查中添加法国域。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example1.com$
RewriteRule (.*)$ http://www.newdomain.com/en/$1 [R=301,L]
</IfModule>

标签: apache.htaccessurl-redirection

解决方案


以下应该有效:

RewriteEngine On

RewriteCond %{HTTP_HOST} example1.com$
RewriteRule (.*) http://www.example.com/en/$1 [R=301,L]

RewriteCond %{HTTP_HOST} example2.com$
RewriteRule (.*) http://www.example.com/fr/$1 [R=301,L]

至于保留永久链接,我认为你不能在这里做,你必须在新域的.htaccess.

你用什么翻译?它是否接受查询参数或能够自行解析 uri?


推荐阅读