現(xiàn)在換用了 ISAPI_Rewrite 3.x 發(fā)現(xiàn)編碼后的字符會(huì)變成亂碼,如果直接使用中文不編碼,則會(huì)被格式化為GBK字符串,因?yàn)?ISAPI_Rewrite 默認(rèn)是以 UTF-8 的編碼接收的.
解決方案
翻了手冊(cè),發(fā)現(xiàn)有一個(gè)配置參數(shù)可以解決該問(wèn)題,代碼如下:
- nounicode|NU
- If NU flag is set, transformation from Unicode to UTF-8 will not take place and all Unicode characters remain encoded in %xx format.
- nounicode|NU
如果標(biāo)志設(shè)置,從Unicode轉(zhuǎn)換為UTF-8不會(huì)發(fā)生,所有的Unicode字符編碼為%xx的保持格式.
在你的RewriteRule 規(guī)則后臺(tái)添加 NU 即可恢復(fù)正常.
關(guān)于ISAPI_Rewrite中文變亂碼解決方法,無(wú)論何種情況,統(tǒng)一解決思想:
1、在傳輸U(kuò)RL時(shí),將中文進(jìn)行urlencode,這樣是沒(méi)錯(cuò)的,把最后一句的規(guī)則添加個(gè)NU參數(shù),RewriteRule ^(.*)$ index.php?$1 [QSA,NU,PT,L]
配置舉例:
傳遞的URL地址,代碼如下:
http://www.companysz.com/sell/search-htm-kw-%C6%BD%B0%E5%B5%E7%C4%D4.html
原來(lái)相應(yīng)的RewriteRule為:
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
修正后的規(guī)則是:
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2 [NU]
shopex原規(guī)則為:
- RewriteBase /
- RewriteCond %{REQUEST_FILENAME} .(html|xml|json|htm|php|php2|php3|php4|php5|phtml|pwml|inc|asp|aspx|ascx|jsp|cfm|cfc|pl|cgi|shtml|shtm|phtm|xml)$
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule ^(.*)$ index.php?$1 [L]
修改后的規(guī)則為:
- RewriteBase /
- RewriteCond %{REQUEST_FILENAME} .(html|xml|json|htm|php|php2|php3|php4|php5|phtml|pwml|inc|asp|aspx|ascx|jsp|cfm|cfc|pl|cgi|shtml|shtm|phtm|xml)$
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule ^(.*)$ index.php?$1 [NU,L]
新聞熱點(diǎn)
疑難解答