伪静态配置
SoeayCMS 的 URL 采用伪静态形式,需要在 Web 服务器配置 rewrite 规则。本章节列出 Nginx、Apache、IIS 三种环境的配置方式。
一、Nginx 配置
打开站点配置文件,在 server { ... } 块内添加以下配置:
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
}
}
# 后台访问限制(可选)
location /admin.php {
# allow 192.168.1.0/24;
# deny all;
}二、Apache 配置(.htaccess)
将以下内容保存为 .htaccess 文件,放在站点根目录:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
# 后台入口保护
RewriteRule ^admin.php - [F,L]三、IIS 配置(URL Rewrite 模块)
Windows 主机或 IIS 服务器,需安装 URL Rewrite 模块,然后在网站根目录创建 web.config 文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="SoeayCMS" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?s={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>四、伪静态模式说明
| 模式 | 示例 | 说明 |
|---|---|---|
| 动态 | /index.php?s=/list/1 | 默认模式,无需 rewrite |
| 伪静态 | /list/1.html | SEO 友好,推荐配置 |
| 自定义 | /news/my-article.html | 通过栏目 filename 自定义 URL 标识 |
五、常见问题排查
- 404 错误:检查 rewrite 规则是否正确写入站点配置。
- 首页正常,内页 404:确认 document_root 指向
public/目录。 - 参数丢失:Apache 规则需加
[QSA]标志;IIS rewrite 需加appendQueryString="true"。
