问题描述

在系统设置中开启伪静态后,访问文章详情等页面出现 404 错误,或样式丢失。

可能原因及解决方案

1. 服务器未配置伪静态规则

开启伪静态后,必须在服务器上配置对应的 URL 重写规则。

Nginx 解决方案:

# 在 server 块中添加以下规则
rewrite ^/(a_[0-9]+)\.html$ /index.php?app=article&action=detail&id=$1 last;
rewrite ^/article/([a-zA-Z0-9_-]+)$ /index.php?app=article&category_slug=$1 last;
rewrite ^/article$ /index.php?app=article last;
rewrite ^/(album_[0-9]+)\.html$ /index.php?app=album&action=detail&id=$1 last;
rewrite ^/album$ /index.php?app=album last;
rewrite ^/(page-[0-9]+)\.html$ /index.php?app=page&action=detail&id=$1 last;

Apache 解决方案:

创建 .htaccess 文件,开启 mod_rewrite 并添加类似规则。

2. 规则顺序错误

伪静态规则顺序会影响匹配结果。

解决方案:将更具体的规则放在前面,通用规则放在后面。

3. 静态资源路径问题

伪静态后,CSS/JS 等静态资源路径可能不正确。

解决方案:确保所有静态资源使用绝对路径(以 / 开头)。