Skip to content

Japanese charaters in code igniter urls

by Mr Kirkland on December 6th, 2007

Code igniter is restrictive over permitted url characters (a good thing!), and it’s simple enough to edit the permitted_uri_config option to add more charaters. However, what if you’re dealing with Japanese charaters in the url?

Well (after a little searching) it turns out that this isn’t too difficult to fix as the config value is a regex and one can add the kanji charater ranges in a similar fashion to the standard ascii ‘a-z’ syntax:


$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';
        ↓
$config['permitted_uri_chars'] = '一-龠ぁ-んァ-ヴーa-zA-Z0-9a-z 0-9~%.:_-';

courtesy of: http://pricewave.blog110.fc2.com/blog-category-4.html

From → webmastering

3 Comments
  1. Hi Chris

    Here’s the other solution (hack) I promised (I should learn to scroll below the fold)

    In Router.php change

    if ( ! preg_match(“|^[".preg_quote($this->config->item('permitted_uri_chars'))."] $|i”, $str))

    to

    if ( ! preg_match(“|^[".preg_quote($this->config->item('permitted_uri_chars'))."] $|i”, rawurlencode($str)))

    A link to the bug report: http://www.codeigniter.com/bug_tracker/bug/2929/

    Derek Allard says the CI guys are working on a better solution but you might want to add yours too so they are aware of what other people are doing.

  2. dude, I freaking looked everywhere for this regex expression for one of my old projects. my google skills are the fail. thanks for posting the solution!

Trackbacks & Pingbacks

  1. Code Igniter Japanese Localisation

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS