2

I have categories name in my database, and some of theme have french characters like é è ê. It works as desired until today when I tried to add another character à to it then I started getting SERVER ERROR

Here is my .htaccess:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([A-Za-z0-9éèêà_-\s]+)-(\d+)\.htm$   classified.php?id=$2 [L]

As you can see, it works fine without the à.

How do I add that thing into the regex ?

Salman A
  • 262,204
  • 82
  • 430
  • 521
Che Jug
  • 417
  • 6
  • 14
  • Check this: [htaccess Mod\_rewrite with accents](http://stackoverflow.com/questions/10451601/htaccess-mod-rewrite-with-accents). In fact, it seems impossible to put accented character inside a .htaccess. – j0k Feb 08 '13 at 20:38
  • The [Apache docs on `mod_rewrite`'s `b` flag](http://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_b) should help you with this. – Carsten Feb 08 '13 at 20:40
  • why not using [^accented]? I think its better for some cases –  Feb 08 '13 at 20:43
  • Aren't accents/foreign characters in urls typically shunned at (unless after ?'s) because its hard for some users to input it if they are typing it by hand into a browser/don't have a foreign keyboard that can easily input those characters/etc. – Class Feb 08 '13 at 20:53
  • Not a duplicate but worth considering: http://stackoverflow.com/questions/1386262/should-i-use-accented-characters-in-urls – Salman A Feb 08 '13 at 20:59

2 Answers2

2

Seems like extended ASCII characters in URL are sent as UTF-8 and url-encoded. For example:

/éèêà-1.htm -> /%C3%A9%C3%A8%C3%AA%C3%A0-1.htm

The above URL can be matched by mod_rewrite like this:

RewriteEngine On
RewriteRule ^(?:\w|\xC3\xA9|\xC3\xA8|\xC3\xAA|\xC3\xA0)+-(\d+)\.htm$ classified.php?id=$1 [L]
Salman A
  • 262,204
  • 82
  • 430
  • 521
2

If you are using all sort of characters and accented letters, then why don't just allow anything to go by?

NOTE: Using this Rule will also allow spaces;

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)-(\d+)\.htm$   classified.php?id=$2 [L]

And later if you decide to limit the regex, lets say you don't want any of these characters # $ % then you have to make exceptions:

   Options +FollowSymlinks
  RewriteEngine on
  RewriteRule ^([^#$%]+)-(\d+)\.htm$   classified.php?id=$2 [L]
Rocks
  • 511
  • 1
  • 6
  • 19