'rm-2ze56e5tmkj3w96y2.mysql.rds.aliyuncs.com', 'user' => 'jimdu', 'pass' => 'Jimdu@912330', 'name' => 'modoer' ); $id = isset($_GET['id']) ? (int)$_GET['id'] : 0; $city = isset($_GET['city']) ? trim($_GET['city']) : ''; $type = isset($_GET['type']) ? trim($_GET['type']) : 'pc'; if (!$id) { header('HTTP/1.0 404 Not Found'); exit; } $cache_dir = ROOT_PATH . '/data/cache/redirect/'; if (!is_dir($cache_dir)) { mkdir($cache_dir, 0755, true); } $cache_file = $cache_dir . 'subject_' . $id . '.cache'; if (file_exists($cache_file) && (time() - filemtime($cache_file)) < 604800) { $subject = unserialize(file_get_contents($cache_file)); } else { try { $pdo = new PDO( "mysql:host={$db_config['host']};dbname={$db_config['name']};charset=utf8", $db_config['user'], $db_config['pass'], array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) ); $stmt = $pdo->prepare(" SELECT s.sid, s.city_id, COALESCE(ad.domain, 'quanguo') as city_domain FROM modoer_subject s LEFT JOIN modoer_area ad ON s.city_id = ad.aid WHERE s.sid = ? AND s.status = 1 LIMIT 1 "); $stmt->execute(array($id)); $subject = $stmt->fetch(PDO::FETCH_ASSOC); file_put_contents($cache_file, serialize($subject)); } catch (Exception $e) { error_log("redirect_subject.php DB Error: " . $e->getMessage()); header('HTTP/1.0 500 Internal Server Error'); exit; } } if (!$subject) { header('HTTP/1.0 404 Not Found'); exit; } $sid = $subject['sid']; $real_city = ($subject['city_id'] == 0) ? 'quanguo' : $subject['city_domain']; // 生成规范URL if ($type == 'mobile') { $canonical_url = "https://www.95ye.com/{$real_city}/gov/m/{$sid}.html"; } else { $canonical_url = "https://www.95ye.com/{$real_city}/gov/{$sid}.html"; } // 判断当前URL中的城市是否与真实城市一致 if ($city == $real_city) { // 已经是正确URL,直接输出内容,不跳转 $_GET['m'] = 'item'; $_GET['act'] = ($type == 'mobile') ? 'mobile' : 'detail'; $_GET['id'] = $sid; if ($type == 'mobile') { $_GET['do'] = 'detail'; } if ($real_city != 'quanguo') { $_GET['city'] = $real_city; } include ROOT_PATH . '/index.php'; exit; } // 城市不正确,301跳转到规范URL header("HTTP/1.1 301 Moved Permanently"); header("Location: $canonical_url"); exit; ?>