Configuration Solution Nginx Server in the WordPress path does not automatically add slashes problem _nginx

Source: Internet
Author: User
Tags nginx server

The problem is this: I am accustomed to add "wp-admin" directly behind the blog address to enter the WordPress backstage, but in the future found no matter what I point to any of the management subkeys, all 404 (Can not find the page), the moment I was embarrassed, this is God horse condition ...

Carefully looked at the link to manage the child, found that they are all similar to "//www.jb51.net/blog/edit.php" such, the key is that they are less "/wp-admin/" This path, the path is wrong, affirmation 404 Bai ...

Know the problem is simple, and the answer is definitely still in Nginx redirect rules, but I do not know how to change, but I also know that the official WordPress must have been solved, so I still very calm to check the document ... Got it

Http://codex.wordpress.org/Nginx

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

Sure enough, I found the solution on the Codex, simply adding a line of slash redirection, and the methods are summarized as follows:

1, Login Shell,vim edit nginx configuration directory (usually in/usr/local/nginx/conf/) under the "wordpress.conf", of course, if you like me to write the Conf file, Then change the corresponding redirect configuration file.

Vim/usr/local/nginx/conf/wordpress.conf

2, the official to the line added to the end of the document on the line

location/blog/{
if ($host!= ' www.jb51.net ') {
rewrite ^/(. *) $//www.jb51.net/$1 permanent;
}
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 (. *)/blog/index.php;
}
}

rewrite/wp-admin$ $scheme://$host $uri/permanent;

3.: Wq Save Restart Nginx

In fact, if you are lazy, directly with "Echo >>" append on the line = =

PS: It is said that Nginx will not automatically at the end of the request plus a slash, will not automatically determine whether the request is a file or a directory. Searching the Nginx slash on the web will refer to the need to add this slash at the end of the request.

The information on the Internet is written like this:

After the index index.html of the location/{} in nginx\conf\vhost.conf, add

if (-D $request _filename) {
 rewrite ^/(. *) ([^/]) $ http://$host/$1$2/permanent;
}


But if you have a port on the back of your Web site, there will be a 403 error when turning.

That is $host variable to lose the port, change to $http _host variable can

All problems are solved by changing the following wording

if (-D $request _filename) {
 rewrite ^/(. *) ([^/]) $ http://$http _host/$1$2/permanent;
}

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.