2

[Update]

Added to the config but still not working

$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';

$config['charset'] = 'UTF-8'; //by default

I have updated Codeigniter from 2.1 to 2.2 then to 3. The issue I have is in the routes in Arabic characters I get redirected to "Object not found" page

$route['cat/(:any)/(:any)'] = 'cat/index/$1/$2';
$route['tour/(:any)/(:any)'] = 'tour/index/$1/$2';
$route['sub_category/(:any)/(:any)'] = 'sub_category/index/$1/$2';
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['order'] = 'order/index/';
$route[urlencode('البومات-الصور')] = 'gallery/index/$1'; //the Arabic one which is not working

And when I echo urlencode('البومات-الصور'); I get

%D8%A7%D9%84%D8%A8%D9%88%D9%85%D8%A7%D8%AA-%D8%A7%D9%84%D8%B5%D9%88%D8%B1 

If I change urlencode('البومات-الصور') to anything in English like $route['albums'] it works fine.

I used the same route without encoding and I get the same error "object not found! The requested URL was not found on this server."

How to solve this issue?

PHP User
  • 2,350
  • 6
  • 46
  • 87
  • I'm not sure if you can do a urlencode for the route path. Since when are you using this function for routes? – itsols May 21 '19 at 01:36
  • @itsols it's in the project since version 2.1 – PHP User May 21 '19 at 08:42
  • I had issues with French accented characters. Did you try rawurlencode? – itsols May 21 '19 at 11:52
  • yes tried rawurlencode instead of urlencode but same issue – PHP User May 21 '19 at 12:58
  • Please do this: First, include a typical complete URL as part of your question. Second, try without encoding the URL at all and post the error message. Third, has your browser environment changed lately (eg: OS or default language or character encoding) ? – itsols May 21 '19 at 16:02
  • URL is already included in the question. updated by testing without encoding. working fine on the server but not on xampp localhost after the upgrade – PHP User May 21 '19 at 16:09
  • Did you move the data from a live server to your local XAMPP? If so, have you checked to see if your DB was originally using utf-8? – itsols May 21 '19 at 16:18
  • Perhaps this link may help... If it doesn't, you should try another fresh installation of XAMPP. https://stackoverflow.com/questions/34564364/how-to-pass-a-persian-string-as-a-argument-in-the-url – itsols May 21 '19 at 16:22
  • DB imported from the server DB and its collation is utf8_geberal_ci and i already executed this: ALTER DATABASE My_DB_Name CHARACTER SET utf8 COLLATE utf8_general_ci; – PHP User May 21 '19 at 16:23
  • @itsols Thank you so much that solved the issue: RewriteRule ^([\s\S]*)$ index.php?rt=$1 [L,B,QSA] you can add it as the answer to accept it that will be useful for others for sure – PHP User May 21 '19 at 16:31

1 Answers1

3

After all that clarification, it came down to how your server was handling character encoding.

Here's a link from another Stack Overflow question that is similar. It has many answers that deal with it in different ways. Here's one that does a rewrite rule for the htaccess file.

RewriteRule ^([\s\S]*)$ index.php?rt=$1 [L,B,QSA]
itsols
  • 5,406
  • 7
  • 51
  • 95