【发布时间】:2018-05-28 11:02:23
【问题描述】:
我有一个域名example.com,它在example.com/en-US/ 上托管一个英文版网站,在example.com/fr-FR/ 上托管一个法文版
到目前为止,我们默认使用英文版本,因此我们会使用 .htaccess 文件中的这些规则将所有请求 example.com 的人重定向到 example.com/en-US/:
Redirect 301 /index.html http://examle.com/en/
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
因此,当您在浏览器中请求 http://exmaple.com 时,服务器将请求 index.html,这将触发重定向到 /en-US/ 目录。
现在我们得到了法语example.fr TLD - 指向同一个网络空间。我现在正在寻找一种将浏览器请求 http://example.fr 重定向到 http://example.com/fr-FR/ 的方法
我已尝试添加以下条件,但它会导致某种循环在 URL 中添加大量 /en-US/s。
请帮帮我,我需要重定向的方法
hxxp://example.com --> hxxp://example.com/en-US/
hxxp://example.fr --> hxxp://example.com/fr-FR/
以及所有明确要求 hxxp://example.com/index.html --> hxxp://example.com/en-US/ 的人
【问题讨论】:
标签: regex apache .htaccess redirect url-rewriting