WordPress is the popular content management system (CMS) written in PHP. MySQL is the backend database server for WordPress. It maintains its URLs with permalink is the full URL of any post, page or any other content on the website. Apache web server uses .htaccess to manage permalinks for WordPress. Nginx doesn’t follow .htaccess, So we need to make changes in Nginx configuration to follow permalinks by Nginx web server.
The default WordPress permalinks are not SEO friendly. Which is not good for the SEO for your application. You need to change permalinks settings to make URLs SEO friendly. To change permalinks, Login to admin panel >> Settings >> Permalinks option.
Default Permalinks:
- https://tecadmin.net/?p=101
SEO Friendly Permalinks:
- https://tecadmin.net/post-name
- https://tecadmin.net/category/post-name
- https://tecadmin.net/2020/01/22/post-name
Setup Nginx for WordPress Permalinks
For example, your blog is running with the main domain. Edit the Nginx configuration file and add the following line under the location section.
location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args; }
If you are running your blog under sub directory URL like /blog, use location a /blog block to your configuration file
location /blog { index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args; }
Save your file and reload the Nginx service.
system restart nginx.service
2 Comments
This does not work. Goes to 404 when used “Post Name” Permalink
I just can’t make this work! I get “File not found” everytime I click a link on the home page.