欢迎来到 Xiuno BBS

针对最新Xiuno5的伪静态规则

Nginx(站点配置 server 块内)

location / {
    try_files $uri $uri/ @rewrite;
}
location @rewrite {
    rewrite ^/(.*)$ /index.php?$1 last;
}

# 后台伪静态(必须在前台规则之前生效)
location /admin/ {
    try_files $uri $uri/ @admin_rewrite;
}
location @admin_rewrite {
    rewrite ^/admin/(.*)$ /admin/index.php?$1 last;
}

Apache(根目录 .htaccess)

稍微复杂点 需先启用 mod_rewrite(a2enmod rewrite,且 AllowOverride All)。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # 后台伪静态(必须在前)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^admin/(.*)$ admin/index.php?$1 [L,QSA]

    # 前台伪静态
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</IfModule>

IIS(根目录 web.config)

需先安装 URL Rewrite 模块(IIS 官方扩展,不是自带的)。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <!-- 后台伪静态(必须在前,stopProcessing 阻止继续匹配) -->
                <rule name="Xiuno Admin" stopProcessing="true">
                    <match url="^admin/(.*)$" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="admin/index.php?{R:1}" appendQueryString="true" />
                </rule>
                <!-- 前台伪静态 -->
                <rule name="Xiuno Front" stopProcessing="true">
                    <match url="^(.*)$" />
                    <conditions logicalGrouping="MatchAll">
                        <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}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

关键注意事项

事项说明
后台规则在前三种服务器都必须让 /admin/ 规则先匹配,否则会被前台规则吞掉,后台登录 POST 到前台 index.php 导致不跳转
Xiuno 端开启conf/conf.php'url_rewrite_on' => 1,打包的纯净版默认已设为 1
子目录部署论坛装在 /bbs/ 子目录时:Nginx 规则路径前加 /bbs/;Apache RewriteBase /bbs/;IIS 规则 url 前加 bbs/
Apache .htaccess必须 AllowOverride All,否则 .htaccess 不生效
IIS URL Rewrite必须单独安装该模块,IIS 默认不带,安装后规则才会生效
静态文件排除三种规则都用 !-f / !-d 排除真实存在的文件(CSS/JS/ 图片),不会误重写
0 0 0
复制成功