1

我有两个旧域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>
4

2 回答 2

1

以下应该有效:

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?

于 2018-10-12T05:08:57.113 回答
0

像这样:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?example1\.com$ [NC]
RewriteRule ^ http://www.newdomain.com/en%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{HTTP_HOST} ^(?:www\.)?example2\.com$ [NC]
RewriteRule ^ http://www.newdomain.com/fr%{REQUEST_URI} [R=301,L,NE]

确保将这些规则保留在其他规则之前作为您的首要规则,并在新浏览器中进行测试以避免旧浏览器缓存。

于 2018-10-12T07:20:58.640 回答