如何使用语言重定向所有网站请求?

发布于 2024-10-03 13:04:52 字数 251 浏览 0 评论 0原文

我正在建立一个有两种语言的网站,英语和法语。 如果有人请求 http://www.abc.com 那么我想将其重定向到 http://abc.com/fr 和 fr 是我的默认语言。

没有语言 en/ 或 fr/ 的任何页面请求应重定向到 fr/。我如何为其编写 htaccess

I am building a website with two language, english and french.
If anyone request http://www.abc.com then i would like to redirect it to http://abc.com/fr and fr is my default language.

anypage request without language en/ or fr/ should redirect to fr/. How do i write htaccess for it

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫雨熙 2024-10-10 13:04:52

将 www 重定向到 /fr

RewriteCond %{HTTP_HOST} !^www\.abc\.com$ [NC] 
RewriteRule .? http://abc.com/fr%{REQUEST_URI} [R=301,L]

如果没有设置 /en,则重定向到 /fr

RewriteCond %{REQUEST_URI} !^/en [NC] 
RewriteRule .? http://abc.com/fr%{REQUEST_URI} [R=301,L]

REQUEST_URI:HTTP 请求行中请求的资源(例如“/索引.html”)。

以下是有关 RewriteCond 的更多信息。

Redirect www to /fr

RewriteCond %{HTTP_HOST} !^www\.abc\.com$ [NC] 
RewriteRule .? http://abc.com/fr%{REQUEST_URI} [R=301,L]

Redirect to /fr if no /en is set

RewriteCond %{REQUEST_URI} !^/en [NC] 
RewriteRule .? http://abc.com/fr%{REQUEST_URI} [R=301,L]

REQUEST_URI: The resource requested in the HTTP request line (e.g. "/index.html").

Here is more information about RewriteCond.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文