
状态码 | 含义 | 在你路由中的作用 | AEO 影响 || :--- | :--- | :--- | :--- || 404 | Not Found未找到 | 用户访问了路由表中未注册的路径时触发 | ✅ 告诉 AI “此页面不存在”防止收录无效链接 || 500 | Internal Server Error服务器内部错误 | 路由已注册但文件丢失或文件格式不符合三段式规范时触发 | ⚠️ 告诉 AI “页面存在但坏了”AI 会稍后重试不会立即删除索引 || 状态码 | 含义 | 使用场景 | AEO 注意事项 || :--- | :--- | :--- | :--- || 200 | OK成功 | 页面正常加载时的默认状态码无需手动写 header | AI 正常抓取并索引内容 || 301 | Moved Permanently永久重定向 | URL 路径变更时使用如 /yz-crane 改为 /yangzhou/25t-crane | ✅ AI 会将旧 URL 的权重完全转移到新 URL || 302 | Found临时重定向 | 临时跳转如维护页面、登录后跳转 | ⚠️ AI 不会转移权重仍保留旧 URL 索引 || 403 | Forbidden禁止访问 | 阻止直接访问 content/ 目录下的原始 txt 文件 | ✅ 保护底层数据不被 AI 绕过模板直接抓取 || 410 | Gone已永久删除 | 明确表示某页面已被有意删除且不会再恢复 | 比 404 更强烈AI 会更快地从索引中移除该页面 |php路由前期准备要建立一个.htacces,路由重定向文件123456789101112131415# 开启重写引擎RewriteEngine On# ✅ 禁止 Apache 自动寻找 index.php强制所有请求走 RewriteDirectoryIndex disabled# 新增显式处理根目录防止被 DirectoryIndex 劫持RewriteRule ^$ index.php?path [L,QSA]# 如果请求的是真实存在的文件或目录直接访问不走PHP路由RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d# 将所有其他请求转发给 index.php并保留原始路径作为 path 参数RewriteRule ^(.*)$ index.php?path$1 [L,QSA]index.php。路径路由文件首页用作路由分发?php //日志生成 error_log(print_r(PATH: [ . ($_GET[path] ?? MISSING) . ], true).PHP_EOL, 3, __DIR__ . /debug.log); // // 第一步获取并清理用户访问的路径 // // isset() 是传统写法避免直接使用 $_GET[path] 导致未定义警告 if (isset($_GET[path])) { // trim() 去除首尾斜杠防止路径匹配失败 $path trim($_GET[path], /); } else { // 如果没有传参默认为空字符串即首页 $path ; } // // 第二步定义显式路由表AEO语义化路径映射 // // 格式干净的URL路径 实际的内容文件路径 // 新增页面只需在此数组中添加一行绝对安全不会产生野页面 $route_map array( content/home.txt, yangzhou content/yangzhou-guide.txt, yangzhou/25t-crane content/yz-25t-overview.txt, yangzhou/25t-crane/rental content/yz-25t-rental.txt, safety/wind-load-standards content/safety-wind.txt ); // // 第三步路由匹配与内容输出 // // array_key_exists() 严格检查键名是否存在于数组中 if (array_key_exists($path, $route_map)) { // 获取对应的内容文件相对路径 $file_path $route_map[$path]; // file_exists() 检查物理文件是否真的存在 if (file_exists($file_path)) { // 读取纯文本内容 $raw_content file_get_contents($file_path); // explode() 按分隔符拆分内容限制最多拆分为3段 $parts explode(||, $raw_content, 3); // count() 校验内容格式是否符合 标题||摘要||正文 的三段式规范 if (count($parts) 3) { $title trim($parts[0]); $desc trim($parts[1]); $body trim($parts[2]); // 【临时测试输出】后续替换为 template.php 的渲染函数 echo h1 . htmlspecialchars($title) . /h1; echo p摘要 . htmlspecialchars($desc) . /p; echo div . $body . /div; } else { // 内容文件格式错误 header(HTTP/1.1 500 Internal Server Error); echo Error: Content file format is invalid.; } } else { // 路由注册了但物理文件丢失 header(HTTP/1.1 500 Internal Server Error); echo Error: Content file not found.; } } else { // // 第四步处理404未注册的路径 // // 必须返回标准的404状态码告知AI爬虫该页面不存在 header(HTTP/1.1 404 Not Found); echo 404 Page Not Found; } ?