I have a link like this
www.example.com/profile.php?name=sagar123
I used this rule:
RewriteRule ^profile/([a-zA-Z0-9_-]+)$ profile.php?name=$1 [L]
and now I can chang my URL to like this:
www.example.com/profile/sagar123
everything is fine but, now I want to use Hindi language characters also like this
www.example.com/profile.php?name=सागर (It’s working fine)
www.example.com/profile/सागर (It is not working and showing Server error)
Please help me to write a rule or regex to accept all ([a-zA-Z0-9_-]+) and also Hindi Character.
Thanks and regards,
2
Answers
Use the
(.*)
regex class to match any type of character.Also, you don’t need the
+
operator at the end in your capturing(
and)
parens, as you’re using^
to indicate the beginning of the URL line, and$
to indicate its end, so a+
greedy operator doesn’t get you anything extra.It should look like…
If you need further info, I recommend taking a look at Apache.org: Apache mod_rewrite Introduction. They cover most of the characters I’ve discussed in this post up to this point:
.
,(
,)
,+
, etc..Hindi chars falls between
u0900-u097F
range. So you can use this inside character class.To answer your question, most regexes(
PCRE
) do not supportu
notation and support format ofx{900}
In python
u
is supported, so :see this for regex matching demonstrating both English and Hindi chars getting matched.
Also, see this for reading literal hindi char mapped to their hex values.