为Typecho、WordPress等博客框架开启伪静态

网站相关 · 2023-01-21 · 144 人浏览

为Typecho、WordPress等博客框架开启伪静态

去除链接中出现的index.php,并获得更好的SEO

Nginx环境

在nginx配置文件夹下(默认在/etc/nginx)进入sites-available,根据默认配置新建一个yourdomain.conf,在location /段加上

# 伪静态重写
if (!-e $request_filename)
{
    rewrite ^(.*)$ /index.php$1 last;
}

或者

try_files $uri $uri/ /index.php?$args;

保存后将该文件链接到sites-enabled文件夹

ln -s /etc/nginx/sites-available/yourdomain.conf /etc/nginx/sites-enabled/yourdomain.conf

然后重启nginx即可

Apache环境

在网站根目录新建文件.htaccess,填入以下内容

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

保存即可,配置立即生效

Typecho WordPress 网站

Powered by Typecho | Theme Jasmine by Kent Liao 萌ICP备20239881号 | 异次元之旅