2015-09-07 75 views
1

我的網站上我有這樣的聯繫:小寫西里爾{QUERY_STRING}

site.com/search.php?str=СТРОКА 
site.com/search.php?str=Строка 

我要讓他們像:

site.com/search.php?str=строка 

即我要小寫{QUERY_STRING}

如何我可以做這個? 我無法使用RewriteMap!

在此先感謝!

+0

爲什麼你不能夠使用RewriteMap指令? – Bobulous

+0

@Bobulous,我的網站是在一個簡單的共享主機上,所以沒有辦法在httpd.conf中聲明RewriteMap – kry4a

回答

0

如果你有ciryllic QUERY_STRING像這樣的鏈接:

site.com/search.php?str=СТРОКА 
site.com/search.php?str=Строка 

而且你想讓他們像如小寫它

site.com/search.php?str=строка 

而且你不能使用RewriteMap指令,請按照下列步驟操作:

1)添加爲.htaccess那些行:

RewriteCond %{QUERY_STRING} %D0%([AF].) 
RewriteRule (.*) rewrite-strtolower.php?rewrite-strtolower-url=$1 [QSA,L] 

%D0%([9A] )|(81) - 檢測[-A]

2)將rewrite-strtolower.php放在.htacces附近

<?php header('Content-Type: text/html; charset=utf-8'); 
    function myUrlEncode($string) { 
     $entities = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D'); 
     $replacements = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]"); 
     return str_replace($entities, $replacements, urlencode($string)); 
    } 

    if(isset($_GET['rewrite-strtolower-url'])) {  
     $url = $_GET['rewrite-strtolower-url']; 
     unset($_GET['rewrite-strtolower-url']); 
     $params = http_build_query($_GET); 
     if(strlen($params)) {   
      $params = '?' . myUrlEncode(mb_strtolower(urldecode($params),"UTF-8")); 
     } 
     header('Location: http://' . $_SERVER['HTTP_HOST'] . '/' . $url . $params, true, 301); 
     exit; 
    } 
    header("HTTP/1.0 404 Not Found"); 
    die('Unable to convert the URL to lowercase. You must supply a URL to work upon.'); 
?> 

3)利潤