Drop Shadow
Drop Shadow

Reputation: 808

How to pass unicode character in URL codeigniter?

I know there is many post on this tropic, but my problem is different. So please don't vote for close this issue.

To allow unicode character in URL I set null in permitted_uri_chars like below

$config['permitted_uri_chars'] = '';

As a result I can pass unicode (Bangali) to URL, but the problem when I send a specific word its show me the below error,

URL : controller/method/অনুষ্ঠান (I am getting error for this word)

enter image description here But the error text should be
"The URI you submitted has disallowed characters", So I am conduced where the problem actually. Thanks in advance.

Upvotes: 0

Views: 1084

Answers (3)

Mike Garcia
Mike Garcia

Reputation: 2122

This is not a problem of CodeIgniter but your .htaccess rewrite rule.

If you want to accept any language for pretty urls open the .htaccess file in your root folder where you have your CI index.php (e.g. public_html) and look for the rewrite rule that contains 'index.php'. Then change the regex to ^([^.]+)/?$

E.g.

RewriteRule ^([^\.]+)/?$ index.php?/$1 [L]

Cheers!

Upvotes: 2

Labib
Labib

Reputation: 51

Keep your $config['permitted_uri_chars'] as defaut
ex. $config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';

to pass unicode characters just follow this simple steps:

  1. While passing value through url use urlencode
    ex. "urlencode('অনুষ্ঠান')"
  2. In controller get that using uri segment and by decoding the url using urldecode.
    ex. urldecode($this->uri->segment(2))

using urlencode and urldecode you can easily pass unicode character in url, not only in codeigniter but also in other php projects.

Hope it helped. Thanks

Upvotes: 0

Jinesh
Jinesh

Reputation: 1580

you have to pass like below :-

$config[’permitted_uri_chars’] = ‘?&=a-z 0-9~%.:_-’;

Upvotes: 0

Related Questions