現在換用了 ISAPI_Rewrite 3.x 發現編碼后的字符會變成亂碼,如果直接使用中文不編碼,則會被格式化為GBK字符串,因為 ISAPI_Rewrite 默認是以 UTF-8 的編碼接收的.
解決方案
翻了手冊,發現有一個配置參數可以解決該問題,代碼如下:
- 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
如果標志設置,從Unicode轉換為UTF-8不會發生,所有的Unicode字符編碼為%xx的保持格式.
在你的RewriteRule 規則后臺添加 NU 即可恢復正常.
關于ISAPI_Rewrite中文變亂碼解決方法,無論何種情況,統一解決思想:
1、在傳輸URL時,將中文進行urlencode,這樣是沒錯的,把最后一句的規則添加個NU參數,RewriteRule ^(.*)$ index.php?$1 [QSA,NU,PT,L]
配置舉例:
傳遞的URL地址,代碼如下:
http://www.49028c.com/sell/search-htm-kw-%C6%BD%B0%E5%B5%E7%C4%D4.html
原來相應的RewriteRule為:
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
修正后的規則是:
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2 [NU]
shopex原規則為:
- 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]
修改后的規則為:
- 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]
新聞熱點
疑難解答