Permanent link implementation of WordPress in Nginx (301,404, etc)

Source: Internet
Author: User

It is actually a very simple method. Modify the nginx. conf file and add the following content:

Copy codeThe Code is as follows: location /{
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;
}
}

Restart nginx.

The following are my configuration file instances:

Www # cat nginx. conf

User www;
Worker_processes 10;

# Error_log logs/error. log;
# Error_log logs/error. log notice;
# Error_log logs/error. log info;

# Pid logs/nginx. pid;

Events {
Worker_connections 1024;
}

Http {
Include mime. types;
Default_type application/octet-stream;

# Log_format main '$ remote_addr-$ remote_user [$ time_local] $ request'
# '"$ Status" $ body_bytes_sent "$ http_referer "'
# '"$ Http_user_agent" "$ http_x_forwarded_for "';

# Access_log logs/access. log main;

Sendfile on;
# Tcp_nopush on;

# Keepalive_timeout 0;
Keepalive_timeout 65;

# Gzip on;

Server {
Listen 80;
Server_name localhost;

# Charset koi8-r;

# Access_log logs/host. access. log main;

Location /{
Root/usr/local/www/nginx;
Index. php index.html index.htm;
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;
}

}

# Error_page 404/404 .html;

# Redirect server error pages to the static page/50x.html
#
Error_page 500 502 503 x.html;
Location =/50x.html {
Root/usr/local/www/nginx-dist;
}

# Proxy the PHP scripts to Apache listening on 127.0.0.1: 80
#
# Location ~ \. Php $ {
# Proxy_pass http: // 127.0.0.1;
#}

# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ \. Php $ {
Root html;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/usr/local/www/nginx $ fastcgi_script_name;
Include fastcgi_params;
}

# Deny access to. htaccess files, if Apache's document root
# Concurs with nginx's one
#
# Location ~ /\. Ht {
# Deny all;
#}
}

# Another virtual host using mix of IP-, name-, and port-based configuration
#
# Server {
# Listen 8000;
# Listen somename: 8080;
# Server_name somename alias another. alias;

# Location /{
# Root html;
# Index index.html index.htm;
#}
#}

# HTTPS server
#
# Server {
# Listen 443;
# Server_name localhost;

# Ssl on;
# Ssl_certificate cert. pem;
# Ssl_certificate_key cert. key;

# Ssl_session_timeout 5 m;

# Ssl_protocols SSLv2 SSLv3 TLSv1;
# Ssl_ciphers ALL :! ADH :! EXPORT56: RC4 + RSA: + HIGH: + MEDIUM: + LOW: + SSLv2: + EXP;
# Ssl_prefer_server_ciphers on;

# Location /{
# Root html;
# Index index.html index.htm;
#}
#}
}

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.