2012-04-29 125 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,將字符更改爲允許的字符,然後我執行重定向。