2011-11-02 23 views
0

我的客戶已經用大寫字母打印了該網站的鏈接。 我有一個CI安裝和需要改變的htaccess或基本控制器(我在莫想很多的選擇),這樣的例子(其用戶類型此到他們的地址欄)工作:Codeigniter - 客戶在URL中使用大寫字母發佈鏈接

http://www.site.com/HAPPY/chappy - >http://www.site.com/happy/chappy

http://www.SITE.com/HaPpy/CHAPpy - >http://www.site.com/happy/chappy

http://WWW.Site.CoM/happy/chappY - >http://www.site.com/happy/chappy

等等... 我似乎無法得到的htaccess簡單地說「採取一切,把它降低案件然後處理它'

這是甚至可能..?

回答

0

是的,你可以將輸入轉換成小字母,只要輸入文字。你可以用javascript來做到這一點。請參閱下面的代碼狙擊它。

function makeLowercase() { 
document.form1.outstring.value = document.form1.instring.value.toLowerCase(); 
} 

<input name="outstring" type="text" value="" size="30" onkeyup="makeLowercase();" onblur="makeLowercase();"> 

或者您也可以使用用strtolower()函數在PHP中爲小寫隱蔽數據,並對其進行處理。

+0

乾杯..我沒有把這個在我的灌輸索引頁: $ _SERVER ['REQUEST_URI'] = strtolower($ _ SERVER ['REQUEST_URI']); 沒有變化..所有上述例子仍然是404頁,而不是重寫。我是猴子嗎?這不是正確的方法嗎? – Beertastic

+0

它是爲你工作? – pinaldesai

+0

嘗試路由http://codeigniter.com/user_guide/general/routing.html – pinaldesai

0

可以使用的.htaccess域名來重寫部分(即一個不區分大小寫反正):

http://www.chrisabernethy.com/force-lower-case-urls-with-mod_rewrite/

+0

把此: 'code'' RewriteMap指令LC INT:tolower的 的RewriteCond%{REQUEST_URI} [AZ] 重寫規則$ {LC:$ 1}(。*)[R = 301,L] '代碼 進我的htaccess文件導致網站失敗,出現服務器錯誤 – Beertastic

+0

刪除這一行'RewriteMap lc int:tolower'刪除了服務器錯誤......這條線究竟是幹什麼的? – Beertastic

+0

[官方文檔](http://httpd.apache.org/docs/2.3/rewrite/rewritemap.html#int) – eudoxos

0

Extend the CI_Exceptions core class用自己的show_error功能。使用原代碼爲show_error,但沿着這些線路增加一個快速檢查,以開頭:

class MY_Exceptions extends CI_Exceptions { 

    /** 
    * General Error Page 
    * 
    * This function takes an error message as input 
    * (either as a string or an array) and displays 
    * it using the specified template. 
    * 
    * @access private 
    * @param string the heading 
    * @param string the message 
    * @param string the template name 
    * @return string 
    */ 
    function show_error($heading, $message, $template = 'error_general', $status_code = 500) 
    { 
     // First try forwarding to all-lowercase URL if there were caps in the request 
     if ($_SERVER['REQUEST_URI'] != strtolower($_SERVER['REQUEST_URI'])) 
     { 
      header('Location: ' . strtolower($_SERVER['REQUEST_URI'])); 
      return; 
     } 
     /* Rest of original function to follow... */ 

自視需要牢記,你可能希望有大寫的URI的其他部分。

你也可以用pre_system (or pre_controller) hook實現類似的功能,但我個人只會這樣做,如果掛鉤已經用於其他目的。

0

您可以擴展核心路由庫以區分大小寫。這就是你放置strtolower()函數的地方。

將它添加到404錯誤處理程序是一個壞主意。

如果你想要LMK的源碼,但它應該是擴展庫,複製1個函數,並添加strtolower()