Fix the unreachable problem by modifying the WordPress fixed link under Nginx

  • 2020-05-09 19:57:45
  • OfStack

This afternoon, I will do the optimization of seo as before. Of course, it involves permalinks. wordpress provides various types of links

      1/%year%/%monthnum%/%day%/%postname%/

      2/%year%/%monthnum%/%postname%/

      3/%year%/%monthnum%/%day%/%postname%.html

      4/%year%/%monthnum%/%postname%.html

      5/%category%/%postname%.html

      6/%post_id%.html

      7/%postname%/

I chose /%postname%.html, pseudo-static, which doesn't seem to make any difference now, but I think I'll do it anyway. The following appeared to modify the fixed link, access to the article will appear 404 error, before I was apache web server, so as long as apache on the next three key, namely

      wordpress has read and write access to.htaccess in the directory
The       fixed-linked directory structure requires support from the mod_rewrite module of the Apache server, so set LoadModule rewrite_module modules/ mod_rewrite.so configuration file httpd.conf to enable.
      is also the Apache configuration file, where the parameter for AllowOverride None in the site directory is set to All. Of course, 1 must restart the Apache service after configuration modification.
Since       is a newly configured local test environment, two problems (2 and 3) occurred at the same time. After the correction of the Settings, the fixed link worked normally.

Now I'm using nginix, so I need to modify the nginix ngnix.conf configuration file to support redirection

Assuming that the server{} section of my wordpress blog is directly put into nginx.conf   (some people are used to write a separate vhost/ directory to store the configuration files of each website for the convenience of management, which should be added according to your own Settings)

     

vi /your_nginx_path/conf/nginx.conf

According to the regular expression rules of nginix,       can be referred to: Nginx's Chinese wiki

              ^ : matches the starting position of the input character               $: matches the end of the days string               + : matches the previous subexpression once or more times               [0-9] : range of numeric characters               $1: call variable

      in server{}   field       "root /websit/wwwroot/;" Below the first line of  , add the following:

            
    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;
    }     rewrite /wp-admin$ $scheme://$host$uri/ permanent;// This line is in case you can't open the background, plug-in pages, etc.

      saved, input      /etc/init d/nginx restart, restart nginix. ok!

This is equivalent to telling nginix to access these and go to its only 1 correct address in the regular expression to open the article.

It seems that /%postname%/ will be linked in Chinese, for seo, you can consider a plug-in WP Slug Translate, it will automatically change the Chinese title to English, can not be connected to the Internet will be changed to pinyin.

It looks like the authorities have come up with a new pha100 pha-3, which is much simpler. Here, let's say I create wordpress.conf in nginx's conf folder and paste the following code into it:

location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

My blog nginx virtual machine configuration file in   conf/vhost/www dabu. info. conf  . Again, under the root line, add 1 line:

include wordpress.conf;

Then restart nginx and you can access it normally


Related articles: