1

好的,我看到一直有人问类似的问题,但是经过多次调整后,我仍然无法正常工作。

我想重定向这个的所有版本:

http://example.com/en/something

对此:

http://example.com/EN/something

例如,这个:

http://example.com/en/2007/06/08/the-3-basic-variations-of-hummus/

对此:

http://example.com/EN/2007/06/08/the-3-basic-variations-of-hummus/

我怎样才能用 htaccess 做到这一点?

谢谢。

4

1 回答 1

3

mod_rewrite - 更改 URL 大小写

只有第二个答案是正确的。

此外,RewriteMap 必须在服务器配置或 VirtualHost 中

我的通用解决方案:

<VirtualHost *:80>
  ...
  <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteMap uppercase int:toupper
    RewriteRule ^/(en|he)(/.*)?$ /${uppercase:$1}$2 [L,R=301]
  </IfModule>
  ...
</VirtualHost>

因此,您可以添加由 | 分隔的语言

对于无法访问服务器或虚拟主机配置以及特定字符串的使用:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^en(/.*)?$ /EN$1 [L,R=301]
</IfModule>

请记住,在每个目录的 RewriteRule 中(.htaccess 是一个每个目录的设置)设置你省略了匹配模式上的第一个斜杠。

在 Ubuntu Server 12.04.2 上检查 Apache 2.2.22

于 2013-06-19T10:20:14.973 回答