WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#7208 closed defect (bug) (invalid)

Problem with Nginx?

Reported by: drhallows Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.6
Component: General Keywords:
Focuses: Cc:

Description

I found a little trouble with
WordPress. If you use Nginx, the permalinks are not seo friendly. I
try all kinds of redirections, but all have the same problem.

For example

Results for: http://mysite.com/?page_id=5

Status : (302) Found
Either http://mysite.com/?page_id=5 is NOT REDIRECTING to any
URL or the redirect is NOT SEARCH ENGINE FRIENDLY.

but when i was using apache, the redirect was 301 (seo friendly).

I am using this kind of redirection in nginx.conf:

if (!-e $request_filename) {

rewrite .+?(/wp-.*) $1 last;
rewrite .+?(/.*\.php)$ $1 last;
rewrite
/index.php last;
}

I also try other kind of redirection, and are not working.

I have visited a lot of blogs WordPress using Nginx, and all have the same problem. It is a problem with the redirection that we are using in Nginx? or is a problem with permalinks in WordPress?

Attachments (1)

nginx.conf (2.8 KB) - added by drhallows 7 years ago.
Nginx Conf Example

Download all attachments as: .zip

Change History (8)

@drhallows7 years ago

Nginx Conf Example

comment:1 follow-up: @DD327 years ago

  • Milestone changed from 2.6 to 2.7
  • Version set to 2.6

Can you just confirm:

  1. Visiting http://mysite.com/?page_id=5 sends a 302 redirect, But doesnt redirect the user?
  2. Visiting http://mysite.com/?page_id=5 sends a 302 redirect, And does redirect the user
  3. Visiting http://mysite.com/?page_id=5 sends a 301 redirect, And does redirect the user
  4. Visiting http://mysite.com/?page_id=5 sends a 302 redirect, but you think it should be sending a 301 to be more search engine friendly

I cant work out if you're refering to 1. or 4. or maybe one of the others..

comment:2 in reply to: ↑ 1 @drhallows7 years ago

Visiting http://mysite.com/?page_id=5 sends a 302 redirect, but you think it should be sending a 301 to be more search engine friendly.

comment:3 @drhallows7 years ago

In apache, is sending a 301, but in nginx, is sending a 302.

comment:4 @DD327 years ago

I see you're using FastCGI, Which is where the problem occurs, See the comment here:
http://trac.wordpress.org/browser/trunk/wp-includes/pluggable.php#L768

comment:5 @drhallows7 years ago

And how can i fix it?

comment:6 @DD327 years ago

You can try commenting out the offending line, If that works, You can either keep it running like that with the modification made, Or you can copy the wp_redirect() function into a plugin and modify it there.

Chances are, It wont work and will instead produce a 500 error. It appears to be a bug in PHP when used as FastCGI; google "fastcgi php 301" and you'll find realted articles.

Your only other option to get a 301 redirect would probably be to change from the PHP FastCGI module to something else.

Suggest cosing as wontfix due to it being a workaround for PHP which is required for compatibility.

comment:7 @jacobsantos7 years ago

  • Milestone 2.7 deleted
  • Resolution set to invalid
  • Status changed from new to closed

See PHP language information for FastCGI redirection.

Note: See TracTickets for help on using tickets.