Nginx Modify wordpress Fixed link causes inaccessible problem resolution _nginx

Source: Internet
Author: User
Tags wordpress blog

Nothing this afternoon, like the previous start to do SEO optimization, of course, involving to a permanent link, WordPress offers a variety of types of link form

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 the/%postname%.html, pseudo static, although now seemingly no difference, but it should be down. The following appears to modify the fixed link, access to the article will appear 404 errors, I used to do the Web server Apache, so as long as the Apache under the three key, namely

WordPress has read and write access to the. htaccess in the directory.
The fixed-link directory structure requires the Mod_rewrite module support of the Apache server, so LoadModule rewrite_module modules/mod_ in the Apache configuration file httpd.conf Rewrite.so is set to Enabled.
The same is the Apache configuration file, where the parameters for allowoverride none under the Site directory are set to all. Of course, after modifying the configuration, be sure to restart the Apache service.
Due to the new configuration of the local test environment, 2, 32 problems occur at the same time, after the setting of the fixed link work properly.

Now I'm using the Nginix, so also want to modify the Nginix ngnix.conf configuration file, so that it supports redirection

Suppose my wordpress blog is server{} paragraph is directly put to put the nginx.conf (some people in order to facilitate management, are accustomed to write a separate vhost/directory to store each site's profile, which will be based on your own settings to add)

Copy Code code as follows:
Vi/your_nginx_path/conf/nginx.conf

According to the rules of Nginix regular expressions, refer to: Nginx's Chinese Wiki

    • ^: match the start position of the input character
    • $: Matches the end position of a string of days
    • +: Match the preceding subexpression one or more times
    • [0-9]: number character range
    • $: Calling variable

In the server{} field, "root/websit/wwwroot/;" (This is the line that specifies the directory where the Web site is located), add the following:

Copy Code code as follows:

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 to prevent open the background, plug-in page, etc. can not open.

After saving, enter/etc/init.d/nginx restart, restart Nginix. It's OK!

The equivalent of telling Nginix to access these and then follow the regular expression to their only correct address to open the article.

Seemingly/%postname%/will be Chinese as a link, in order to SEO, you can consider a plug-in WP Slug Translate, it will automatically change the Chinese title for English, can not be switched to pinyin.

It seems that the government has given a new pha100 pha-3, and it is much simpler. This assumes that I create a wordpress.conf under the Nginx Conf folder and paste the following code in:

Copy Code code as follows:
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 Root, add a line:

Copy Code code as follows:
Include wordpress.conf;

Then restart the Nginx, and you'll be able to access it normally.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.