2

I have RewriteRule ^([[:alpha:]]+)$ do-something.php?parameter=$1 and it works for URLs like .../Virtanen. For .../Mähönen I can use ([ÄÖäö[:alpha:]]+, but that of course fails for, say, .../Vadén. How to make :alpha: interpreted as Unicode characters?

This has been asked several times, but no answer I found works.

I use Apache 2.4.

1 Answer 1

3

mod_rewrite documentation at https://httpd.apache.org/docs/2.4/rewrite/intro.html#regex says:

mod_rewrite uses the Perl Compatible Regular Expression vocabulary. In this document, we do not attempt to provide a detailed reference to regular expressions. For that, we recommend the PCRE man pages, the Perl regular expression man page, and Mastering Regular Expressions, by Jeffrey Friedl.

In "PCRE" you have the liberty to match through Unicode properties, see https://perldoc.perl.org/perluniprops#Properties-accessible-through-%5Cp%7B%7D-and-%5CP%7B%7D

Which means, if really properly implemented by mod_rewrite that \p{Block: Latin_1} in your expression would match any character in the "Latin 1 Supplement" block, which is the case for characters ÄÖäö.

There are of course other ways to select, depending on expected input. You have even \p{General_Category: Letter} for any character that is defined as a "letter" in the Unicode database.

This has been asked several times, but no answer I found works.

When asking, it could help to specify, even quickly, what you tried already that doesn't work. That allows to avoid anyone repeating something you already know not to work. I did not try the above, so maybe it doesn't work (but should based on documentation) or maybe you tried already?

12
  • Unfortunately at least RewriteRule ^\p{Block: Latin_1}$ ..., RewriteRule ^\p\{Block: Latin_1\}$ ...and RewriteRule ^\\p\{Block: Latin_1\}$ ... all give just an internal server error. I try to re-read some pages and modify question to that it tells what I have already tried. Jun 29, 2022 at 17:01
  • 1
    "I would try also without the space after :" - the space would certainly cause an error in Apache config files (since the space is the argument delimiter). Either remove it as suggested, or enclose the entire argument in double quotes. See also: regular-expressions.info/unicode.html
    – MrWhite
    Jun 29, 2022 at 17:27
  • 1
    ^\\p{General_Category:Letter}$ - You shouldn't escape the backslash.
    – MrWhite
    Jun 29, 2022 at 17:28
  • 1
    Progress! \p{Latin} works, for example \p{Latin_1} does not. But it seems that Latin does not detect ä or ö. Anyways, I guess I can proceed with this to see if I found a solution. Jun 29, 2022 at 17:53
  • 1
    The RewriteRule pattern (as you are using here) matches against the %-decoded URL-path, so this should not be a percent encoding issue. (As you say, you are able to match a "plain ä"). @JoriMäntysalo
    – MrWhite
    Jun 30, 2022 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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