How to use Codeigniter routes with UTF-8 like Arabic characters 404 How to use Codeigniter routes with UTF-8 like Arabic characters 404 codeigniter codeigniter

How to use Codeigniter routes with UTF-8 like Arabic characters 404


The solution is as simple as this:

in the routes.php config file do the following:

$mission = urlencode('مهمتنا');$route['^(en|ar)/'.$mission] = "pages/index/".$mission;

no need to change the permitted_uri_chars in the config.php config file.

if the error was with the permitted_uri_chars the output would have been 400 "The URI you submitted has disallowed characters." not 404as you can see here at system/core/URI.php, on line 231:

if (!preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str)){    show_error('The URI you submitted has disallowed characters.', 400);}


I tried this and it's working with me just add this in .htaccess

RewriteRule ^([\s\S]*)$ index.php?rt=$1 [L,B,QSA]


Try to encode the arabic characters, so that instead of using:

$config['permitted_uri_chars']  .= 'لإ-لآ-أ-لآ-ض-ص-ث-ق-ف-غ-ع-ه-خ-ح-ج-د-ط-ك-م-ن-ت-ا-ل-ب-ي-س-ش-ئ-ء-ؤ-ر-ل-ا-ى-ة-و-ز-ظ-إ';

You might want to use:

$config['permitted_uri_chars'] .= '%D9%84%D8%A5-%D9%84%D8%A2-%D8%A3-%D9%84%D8%A2-%D8%B6-%D8%B5-%D8%AB-%D9%82-%D9%81-%D8%BA-%D8%B9-%D9%87-%D8%AE-%D8%AD-%D8%AC-%D8%AF-%D8%B7-%D9%83-%D9%85-%D9%86-%D8%AA-%D8%A7-%D9%84-%D8%A8-%D9%8A-%D8%B3-%D8%B4-%D8%A6-%D8%A1-%D8%A4-%D8%B1-%D9%84-%D8%A7-%D9%89-%D8%A9-%D9%88-%D8%B2-%D8%B8-%D8%A5';

Also you might want to remove the "-" character from the config item so the "permitted_uri_chars" config item would like:

$config['permitted_uri_chars'] .= '%D8%A2%D8%A7%D8%A8%D9%BE%D8%AA%D8%AB%D8%AC%DA%86%D8%AD%D8%AE%D8%AF%D8%B0%D8%B1%D8%B2%D8%B3%D8%B4%D8%B5%D8%B6%D8%B7%D8%B8%D8%B9%D8%BA%D9%81%D9%82%DA%A9%DA%AF%D9%84%D9%85%D9%86%D9%88%D9%87%DB%8C%D9%8A%DB%B1%DB%B2%DB%B3%DB%B4%DB%B5%DB%B6%DB%B7%DB%B8%DB%B9%DB%B0';

This should solve your issue as those characters are being handled in the encoded form instead of their original values.

Hope this helps.