Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running an Ubuntu 10.04 LTS, Apache version 2.2.14.

On httpd.conf I've a rewrite rule that look like this:

RewriteRule (*UTF8)^/users/([^/])([^/]+)/(.*)$ /users/$1/$2/$1$2/$3 [L]    

The idea is to set directories to internationalized domain name (IDN) in my server.

I keep getting

RewriteRule: cannot compile regular expression

Any idea if it is the demon version or something else?

share|improve this question
Have you tried running it through a regexp validator? Returning as invalid for me. What is the purpose of (*UTF-8) at the start before the opening ^, I've never seen anything like that before and can't find it documented, yet when I remove it the regexp becomes valid – Smudge Nov 23 '11 at 9:29
Well Sam, I need that the IDN's will be in UTF8 and not in asccii. Do you know a way that I can do that? I saw a working example that does it like that and the only difference that I can think of is the demon version... – koby Nov 23 '11 at 9:36
Any chance you could post the example? As I understood it 1) nothing should come before the ^ within the rewrite rule, 2) If you want to match UTF-8 characters the code you have (([^/])) should work (As would .* or (.+)) and 3) Browsers encode UTF-8 characters outside the standard ASCII range (So á becomes %C3%A1 when sent to the server). Try removing (*UTF-8) from the start of the regex and see if it works – Smudge Nov 23 '11 at 9:42
Sam, The example is similar to my use. As I understand it, IDN's translate to "xn--" (Bü translated to, Wikipedia example). So removing the UTF8 might remove the error, but will not work... – koby Nov 23 '11 at 10:00
@koby Any URL to show where this "working example" is? – Olivier Pons Nov 23 '11 at 11:21

(*UTF8) is not a valid regular expression, and I'm not sure why you're requesting it--things like .* and the like in your regular expression will match any character, UTF8 encoded or not. What you're referring to is perl--not mod_rewrite, which requires explicit enabling of utf8 support.

For mod_rewrite, you're trying to treat a particular encoding in a special way, and its just not needed in this case.


RewriteRule ^/users/(.*)$ /newusers/$1 [L]

will match:


and so on. However, keep in mind that using character classes like [a-zA-Z] will NOT match utf8.

share|improve this answer
I know that (*UTF8) if not a valid expression, all I'm trying to do is to make sure that the expression I'm getting is UTF8 and not ascii. if I'm making a wget call for Bü my server ip), I'm getting ascii on the apache and my regex is no good. How can I convert it to UTF8? – koby Nov 25 '11 at 7:15
The encoding isn't done by Apache; its done by your browser. There's no such thing as UTF8 encoding in a URL. When you type in /users/café, that will get percent encoded to /users/caf%E9. Your browser may do this transparently, but Apache will convert it back to UTF8 automatically. So if you wanted to match anything that ends in é, you could use /users/(.*\XE9) (note the hex encoded string in the rule). However, to match ANYTHING, regardless of unicode, . will match any character, be it UTF-8, Latin-1, ascii, etc.. – Andrew M. Nov 25 '11 at 15:36
I'm trying to redirect a request. all browsers are encoding it to UTF8, but other application (wget,bots etc) are sending it with ascii encoding so the regex wont work for both, and I need it to work on both... – koby Nov 25 '11 at 19:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.