mod_rewrite 适用于带有 en、es 的 URL,但不适用于 zh-tw 和 zh-cn?

发布于 2024-09-12 14:46:48 字数 1161 浏览 2 评论 0 原文

我的网站采用 4 种语言,并通过以下模式进行访问:

http://example/index.php?lang=en
http://example/index.php?lang=es
http://example/index.php?lang=zh-tw
http://example/index.php?lang=zh-cn

我在 .htaccess 文件中使用以下 mod_rewrite 规则:

RewriteEngine on
RewriteRule ^([a-z]{2}(-[A-Z]{2})?)/(.*) $3?lang=$1 [L,QSA]

因此输入 http://example/en/index.phphttp://example/es/index.php 有效地将我重定向到 http://example/index.php?lang=enhttp: //example/index.php?lang=es 分别。但这不适用于 http://example/index.php?lang=zh-tw http://example/index.php?lang=zh-cn

它只是说:在此服务器上找不到请求的文档。

这与连字符(zh-tw 和 zh-cn)有关吗?

我该如何解决这个问题?

My sites are in 4 languages and they are accessed with the following pattern:

http://example/index.php?lang=en
http://example/index.php?lang=es
http://example/index.php?lang=zh-tw
http://example/index.php?lang=zh-cn

I'm using the following mod_rewrite rule in my .htaccess file:

RewriteEngine on
RewriteRule ^([a-z]{2}(-[A-Z]{2})?)/(.*) $3?lang=$1 [L,QSA]

So typing http://example/en/index.php and http://example/es/index.php efectively redirects me to http://example/index.php?lang=en and http://example/index.php?lang=es respectively. But that doesn't work with http://example/index.php?lang=zh-tw and http://example/index.php?lang=zh-cn

It just says: The requested document was not found on this server.

It is something to do with the hyphen (zh-tw and zh-cn)?

How can I fix this problem?

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

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

发布评论

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

评论(1

我爱人 2024-09-19 14:46:48

[AZ] 替换为 [az]

Replace [A-Z] with [a-z].

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