apache - htaccess 将特定语言的域重定向到新域
问题描述
我有两个旧域http://example1.com(英语)和http://example2.com(法语),并希望它们重定向到我的新域,例如:
此外,我想确保永久链接在重定向后也保持不变。
例如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>
解决方案
以下应该有效:
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?
推荐阅读
- html - height="x%" 不起作用
- api - Apostrophe CMS 中 api 调用的唯一字段类型和特定 GET 参数
- keras - 无效参数“class_mode”和 _make_train_function **self._function_kwargs)
- ruby-on-rails - Rails - 关联三个模型
- wpf - WPF 窗口背景图像中的 URI 路径
- java - 将字符串转换为 JSONArray,然后列表
- mysql - T-sql 查询问题
- javascript - 从plotly javascript中提取所有属性
- excel - Excel VBA:输入命令按钮时使用复选框值
- r - 为什么此错误会发生“使用'.'的数据框中的名称重复?”?