如何允许URL在CodeIgniter中包含下划线字符


How to allow when URL contain underscore character in CodeIgniter

我是CodeIgniter的新手,有URL的问题。当我打开我的URL像www.abc.com/france它的工作很好,但当URL像www.abc.com/united_state页面打开,但页面的所有内容没有正确显示。分页也不工作(只显示一个页面)。控制器代码是

 $searchkey =$this->uri->segment(3);
     $searchkey  = urldecode(str_replace('_',' ',$searchkey));
     $checkin =$this->uri->segment(4);
    $checkout = $this->uri->segment(5);
    $newkey=$this->uri->segment(5);
                 }
if(preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $checkin) && preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $checkout))
    {
        //echo "hello";
        $last1=$last1+2;
        switch($last1)
{
case 5:

$searchkey=$this->uri->segment(3);

$column = "CountryName";$master = "country";$master2 = "CountryName";
$getdata = $this->searchdata_model->get_listing_data_list($column,$searchkey,$checkin,$checkout,$master,$newkey);
$latest_listing = $this->searchdata_model->get_lastest_properties($searchkey,$master2);
$data['latest_listing'] = $latest_listing;
break;

我认为问题是在preg_match函数

允许config/config.php文件中出现下划线

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';