前由
wordpress的固定链接对于博客的seo优化是非常重要的。因为有些默认设置并不怎么友好,所以我们可以自定义设置自己的想要的固定链接,比如自定义连接结构为:/%post_id%.html。但是往往我们更改之后会出现404页面,这是网站的伪静态出了问题。 下面是在不同环境下的不同解决方法。
1. nginx
如果使用宝塔建站那么就简单许多,打开网站设置,写入伪静态规则保存即可。
location / { if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } } 如果是其他环境,找到网站的 nginx.conf ,例如/usr/local/nginx/conf/vhost/huahai.club.conf,在 server 的大括号内添加上面代码并保存即可。记得重启 nginx使之生效。 2、apache 建立.htaccess文件,写入以下代码,放在 wordpress 根目录。
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> 3、IIS 详见https://cloud.tencent.com/developer/article/1626270