2012-04-29 130 views
0

400错误的请求在我笨的项目,我有以下htaccess文件(使用表单助手)从URL需要帮助解决的笨项目

RewriteEngine on 
RewriteCond $1 !^(index\.php|js|media|style|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

我使用的搜索表单中删除的index.php。由于它是基于POST的,因此我创建了一个名为“pre_search”的控制器,将其重定向到搜索控制器,以便发布的数据将在URL中可见,并且可以将其与URI helper的段方法一起使用。

所以我pre_search控制器

<?php 

class Presearch extends CI_Controller { 

    //just to make form POST data visible in URL string for search 
    public function index() { 
     redirect('search/' . $this->input->post('term')); 
    } 
} 

和搜索控制器做实际的搜索。同时,我允许URL中的所有字符进行测试。

$config['permitted_uri_chars'] = ''; 

我现在的问题是,当我在URL中有百分比符号(%)时,它显示错误的请求。我认为这是apache的回应,codeigniter与它无关。

经过一番研究,我发现,有人建议通过修改htaccess的这样

RewriteRule ^(.*)$ /index.php/$1 [B,L] 

我已经试过这个方法,它打破了一切努力解决这个问题。

自%征未编码的,我想也用在我的pre_search控制器这样

redirect('search/' . urlencode($this->input->post('term'))); 

但没有解决问题。

那么解决这个问题的最好方法是什么?我知道这是Apache的问题。我只是说明我的代码字,以澄清我的意图。

在此先感谢

迪帕克

回答

0

我做同样的,这些都是我的PARAMS,我也发现了这个链接它可以帮助你与htaccess的http://www.dracos.co.uk/code/apache-rewrite-problem/

$this->load->library('form_validation'); 
$this->form_validation->set_rules('s', '','trim|min_length[3]|required|xss_clean'); 
if ($this->form_validation->run() == FALSE): 
    $this->session->set_flashdata('errorMsg', form_error('s')); 
    redirect($this->session->userdata['redirectUrl']); 
else: 
    redirect(base_url() . $this->lang->line('link_search') . '/' . $this->functions->convertToUrl($this->functions->secureString($this->input->post('s', TRUE)))); 
endif; 

我的配置值

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

我将POST转换为legi ble url,将字符更改为允许的字符,然后我执行重定向。