2013-02-18 134 views
0

我想有網址像有URL中的特殊字符在笨

http://www.example.com/(*)

但笨不允許我這樣做。當我嘗試訪問某些URL時,我收到404錯誤(並且存在請求的頁面)。

我知道我可以在URL中設置允許的字符,但我想過編碼它。但是,如果我做這樣的事情:

http://www.example.com/<?php echo rawurlencode(string) ?> 

甚至:

http://www.example.com/<?php echo rawurlencode(rawurlencode(string)) ?> 

我還是得到了404,這是爲什麼? '%'是允許的字符,所以它爲什麼不起作用?我能做些什麼來解決它?

回答

0

當試圖通過urlencoded串到URI如果編碼字符串有/它會產生一個錯誤,笨將嘗試解析此爲段,從而使一個404,你需要使用的是查詢字符串。

$string = rawurlencode(string)

http://www.example.com/class/method/?string=$string

然後在你的方法

使用get

function method() 
{ 
    $this->input->get('string'); 

} 
+0

它破壞了seo友好的URL以及我對結構的整體概念。在普通的PHP中,我可以在2-3行代碼中實現我想要的內容。我如何在codeigniter中存檔它? – user1010446 2013-02-18 08:03:23

1

您可以通過的config/config.php文件permitted_uri_chars鍵允許某些跡象。

但是,雖然我不完全確定,但我相信這些默認情況下會受到限制以提高安全性。由於相關解釋說明:

/* 
|-------------------------------------------------------------------------- 
| Allowed URL Characters 
|-------------------------------------------------------------------------- 
| 
| This lets you specify with a regular expression which characters are permitted 
| within your URLs. When someone tries to submit a URL with disallowed 
| characters they will get a warning message. 
| 
| As a security measure you are STRONGLY encouraged to restrict URLs to 
| as few characters as possible. By default only these are allowed: a-z 0-9~%.:_- 
| 
| Leave blank to allow all characters -- but only if you are insane. 
| 
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!! 
| 
*/ 

例如,什麼是那麼整齊了當前的設置是你讓足夠少的URI來解析的ID,而不用擔心有他們的''""或similiar損害。當然有自動和手動$this->db->escape(),但這只是增加了更多失敗者。

0

如果您想在URL中使用斜槓/,請使用雙重原始編碼。例如:

$string = rawurlencode(rawurlencode('/sth/sth'));