1

o.k, I see that similar questions are asked all the time, but after many tweaks I still can't get it to work.

I'd like to redirect all versions of this:

http://example.com/en/something

To this:

http://example.com/EN/something

For example, this:

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

To this:

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

How can I do it with htaccess?

Thanks.

4sha
  • 326
  • 1
  • 3
  • 12
Tal Galili
  • 24,605
  • 44
  • 129
  • 187

1 Answers1

3

mod_rewrite - change URL case

Only that the second answer is the right one.

Also, RewriteMap must be in the Server config or VirtualHost

My solution for generic use:

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

So you can add languages separated by |

For use with no access to server or virtual host configuration and for specific strings:

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

Remember that in RewriteRule in per-directory (.htaccess is a per-directory setting) setting you omit the first slash on the match pattern.

Checked on Apache 2.2.22 on Ubuntu Server 12.04.2

Community
  • 1
  • 1