标签 wordpress 下的文章

Nginx上搭建WordPress如何设置伪静态

设置 > 固定链接 中设置好固定链接的格式,保存后会显示 Apache 的 URL Rewrite 代码。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

把它转换为 Nginx 的 URL Rewrite 代码即可(转换工具)。当然,(平滑)重启 Nginx 是必须的。

location / {
    root /var/www/joycc;
    index index.html index.htm index.php;

    rewrite ^/index.php$ /- last;
    if (!-e $request_filename)
    {
        rewrite ^/. /blog/index.php last;
    }
}

附:Wordpress 固定链接的结构标签

%year% – 发表的年份,4位数
%monthnum% – 发表的月份,2位数
%day% – 发表日期中的天,2位数
%hour%, %minute%, %second% – 分别表示发表的时、分、秒
%postname% – 文章标题的别名,空格会被转化为中划线(-)
%post_id% – 文章唯一id
%category% – 文章分类的别名
%author% – 作者的别名,如 admin