WordPress URL Rewrite cho URL tĩnh trên IIS Host - Giải pháp hoàn hảo
Đầu tiên, nhà cung cấp hosting của bạn cần hỗ trợ trang lỗi tùy chỉnh. Sau đó tạo file 404.php ở định dạng UTF-8 với code sau:
<?phpheader("HTTP/1.1 200 OK");$ori_qs = strtolower($_SERVER['QUERY_STRING']);$pattern = '/[^;]+;[^:]+:\/\/[^\/]+(\/[^\?]*)(?:\?(.*))?/i';
preg_match($pattern, $ori_qs, $matches);$_SERVER['PATH_INFO'] = $matches[1] . '?' . $matches[2];$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];$query_args = explode('&', $matches[2]);unset($_GET);foreach ($query_args as $arg){$the_arg = explode('=', $arg);$_GET[$the_arg[0]] = $the_arg[1];}
include('index.php');?>Sau khi tạo, upload lên thư mục gốc của website, sau đó đặt trang lỗi tùy chỉnh thành 404.php. Bằng cách này bạn có thể vào Dashboard - Settings - Permalinks để bật URL tĩnh. Tuy nhiên, phương pháp này làm cho các tag tiếng Trung và một số tag liên quan không tìm thấy. Giải pháp là tìm code sau trong wp-include/classes.php:
if ( isset($_SERVER['PATH_INFO']) )$pathinfo = $_SERVER['PATH_INFO'];else$pathinfo = '';$pathinfo_array = explode('?', $pathinfo);$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);$req_uri = $_SERVER['REQUEST_URI'];Đổi thành:
if ( isset($_SERVER['PATH_INFO']) )$pathinfo = mb_convert_encoding($_SERVER['PATH_INFO'], 'utf-8', 'GBK');else$pathinfo = ";$pathinfo_array = explode('?', $pathinfo);$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);$req_uri = mb_convert_encoding($_SERVER['REQUEST_URI'], 'utf-8', 'GBK');