伪静态如何设置?

来源: 官方手册 2026-09-18

服务器伪静态规则

先确定您的服务器环境,然后根据环境选择下列伪静态规则配置:

Nginx(通用)

在网站配置文件的 server 块中添加:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

Nginx(宝塔面板)

宝塔面板 → 网站设置 → 伪静态,粘贴:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

Apache(通用)

在网站根目录 .htaccess 文件中写入:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</IfModule>

IIS(通用)

在网站根目录创建 web.config 文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="douhao">
                    <match url="^(.*)$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php?{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

后台设置及URL格式说明

后台 → 网站设置 → 伪静态设置 Tab。


页面类型格式示例
文章详情页【前缀】【ID/哈希/MD5】.htmlarticle-123.html
文章分类页【前缀】【ID/哈希/MD5】.htmlcategory-1.html
产品详情页【前缀】【ID/哈希/MD5】.htmlproduct-123.html
产品分类页【前缀】【ID/哈希/MD5】.htmlproduct-category-1.html

前缀自定义

每个页面类型的前缀都可以自定义,例如将 article- 改为 post-  或者  post/。

我要提问

写下您的问题,我们会尽快为您解答

提示:请简明扼要地描述您的问题