pache和Nginx是Linux系统常用的建站环境,大多数Linux虚拟主机使用的就是Apache环境,常用建站环境一键包搭建的是在Nginx环境下。在两种环境下安装WordPress网站程序,设置固定链接自定义结构时,会出现404错误,那就是主机不支持WordPress伪静态规则。现在有很多服务器面板如:宝塔,可以直接勾选就能设置伪静态,如果你正在用,就可以不用继续看了。

我们如何实现WordPress伪静态设置。

1、设置固定链接

这里我们在【设置】-【固定链接】选择设置伪静态规则。

WordPress教程-Nginx和Apache环境伪静态设置方法-痴痴资源网

Apache和Nginx伪静态设置方法和规则文件

1、Apache,需要在网站根目录 .htaccess 文件中添加以下代码

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

2、Nginx,若系统没有自带配置,那么我们需要手动配置

location / {
  try_files <span class="hljs-variable">$uri</span> <span class="hljs-variable">$uri</span>/ /index.php?<span class="hljs-variable">$args</span>;
}

<span class="hljs-comment"># Add trailing slash to */wp-admin requests.</span>
rewrite /wp-admin$ <span class="hljs-variable">$scheme</span>:<span class="hljs-comment">//$host$uri/ permanent;</span>