I want to add a directive in my .htaccess, such that if the browser is pointed at a URI containing %E4 (ä) - or any other special character - the .htaccess automatically rewrites %E4 (ä) as %C3%A4 (ä).

In summary, I want .htaccess to convert Win-1252 percent-encoding to UTF-8 percent-encoding.

I know I can do this by adding a series of mod_rewrite rules - but I was wondering if there is a native .htaccess directive that will take care of this.


This is as far as I've got on my own so far (I have many more entries in my .htaccess than in the list below, but I've abridged the list to äéîöü for example purposes):

RewriteRule ([^\ä]*)\ä([^\ä]*\ä[^\/]*)(\/[.*])? $1%C3%A4$2$3 [N]
RewriteRule ([^\ä]*)\ä([^\ä]*)$ http://www.domain.com/$1%C3%A4$2 [NE,R=301]

RewriteRule ([^\é]*)\é([^\é]*\é[^\/]*)(\/[.*])? $1%C3%A9$2$3 [N]
RewriteRule ([^\é]*)\é([^\é]*)$ http://www.domain.com/$1%C3%A9$2 [NE,R=301]

RewriteRule ([^\î]*)\î([^\î]*\î[^\/]*)(\/[.*])? $1%C3%AE$2$3 [N]
RewriteRule ([^\î]*)\î([^\î]*)$ http://www.domain.com/$1%C3%AE$2 [NE,R=301]

RewriteRule ([^\ö]*)\ö([^\ö]*\ö[^\/]*)(\/[.*])? $1%C3%B6$2$3 [N]
RewriteRule ([^\ö]*)\ö([^\ö]*)$ http://www.domain.com/$1%C3%B6$2 [NE,R=301]

RewriteRule ([^\ü]*)\ü([^\ü]*\ü[^\/]*)(\/[.*])? $1%C3%BC$2$3 [N]
RewriteRule ([^\ü]*)\ü([^\ü]*)$ http://www.domain.com/$1%C3%BC$2 [NE,R=301]

Does anyone know:

1) How I can tidy this up?

2) It won't work if there is a more than one special character (single occurrence or multiple occurrences) in the URI. Is there any straightforward way to ensure the rules will handle multiple special characters?

  • Should I ask this question over at Server Fault, instead? – Rounin Nov 26 '14 at 22:45
  • Okay, I'm going to retire the question here. If you do have any ideas (which I'd be very grateful to read!), please answer the question above at Server Fault: serverfault.com/questions/648308/… – Rounin Dec 7 '14 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.