WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#6779 closed defect (bug) (fixed)

domain.com to www.domain.com redirect is a 302 redirect

Reported by: Analogpoint Owned by:
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.9
Component: Permalinks Keywords: has-patch
Focuses: Cc:

Description

The redirect from domain.com to www.domain.com that Wordpress automatically does, is a 302 temporary redirect. This can cause duplicate content problems with the major search engines, and should be changed to a 301 Permanent Redirect to take care of the problem.

Attachments (1)

pluggable.php.diff (409 bytes) - added by error 6 years ago.
Patch wp_redirect() to send correct $status code

Download all attachments as: .zip

Change History (8)

comment:1 @markjaquith7 years ago

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

We try a 301 redirect. For certain server setups like IIS and FastCGI, we are not permitted to issue a new status header, so those setups might default to a 302 redirect. See wp_redirect() in wp-includes/pluggable.php

@error6 years ago

Patch wp_redirect() to send correct $status code

comment:2 follow-up: @error6 years ago

  • Component changed from General to Permalinks
  • Keywords has-patch added
  • Milestone set to 2.9
  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Version changed from 2.5 to 2.9

This is still a serious issue. At the time this was originally opened there was no good fix. Now that WP requires PHP 4.3 or later, a good fix is available: use the http_response_code parameter in the PHP header() call which was added in 4.3. A patch is attached. This is working for me on my nginx/fastcgi setup.

comment:3 @error6 years ago

I forgot to note that this issue doesn't just afffect www vs. non-www, it affects all internal permalink redirects, such as adding the trailing slash, redirecting GET requests for the trackback URI, etc. So from a search engine optimization perspective this is quite a serious problem.

comment:6 @markjaquith6 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [12358]) Use http_response_code for wp_redirect(), so that fastcgi hosts always get 301 redirect love. props error. fixes #6779

comment:7 in reply to: ↑ 2 @markjaquith6 years ago

Replying to error:

This is still a serious issue. At the time this was originally opened there was no good fix. Now that WP requires PHP 4.3 or later, a good fix is available: use the http_response_code parameter in the PHP header() call which was added in 4.3. A patch is attached. This is working for me on my nginx/fastcgi setup.

Thanks for sticking with this, error! And thanks for the historical context, Denis — that was helpful in jogging my memory. :-)

Note: See TracTickets for help on using tickets.