WordPress更改固定链接后404

前言

一开始我是使用xampp在本地搭建Apache+Msql+PHP环境学习wordpress,后来我迁移网站到lNMP后,除了主页能正常打开,其他页面均显示404错误,在网上查找了一下,原因是因为从apache迁移到nginx后没有设置Nginxg伪静态,设置后即可正常。

Apache 伪静态规则

在WordPress站点的根目录创建一个名为”.htaccess”的文件,添加并保存以下内容,然后重启Apache。

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

Nginx伪静态规则

创建一个wordpress.conf文件,填写以下配置伪静态规则。

				
					location / {
	try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
				
			

然后在nginx里添加引用路径。例如我把静态规则文件到转到和nginx.conf所在同一目录rewrite目录下:include rewrite/wordpress.conf;

然后执行“nginx -t”测试nginx配置有否有问题,出现”successful”即为通过。

然后输入执行以下命令重启nginx

				
					
systemctl restart nginx
				
			
0 0 投票数
文章评分
订阅评论
提醒
guest
0 评论
最旧
最新 最多投票
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论!x