WordPress.org

Ready to get started?Download WordPress

Forums

I want to change 302 to 301 canonical redirect? (2 posts)

  1. Kejatz
    Member
    Posted 4 years ago #

    I saw that WP does 302 redirect for canonical URLs. I need it to do 301 redirect. Where in the code can I change this? I saw that wp-app.php file has the following code:

    /**
    	 * Display Redirect (302) content and set status headers.
    	 *
    	 * @since 2.3.0
    	 */
    	function redirect($url) {
    
    		log_app('Status','302: Redirect');
    		$escaped_url = esc_attr($url);
    		$content = <<<EOD
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html>
      <head>
        <title>302 Found</title>
      </head>
    <body>
      <h1>Found</h1>
      <p>The document has moved <a href="$escaped_url">here</a>.</p>
      </body>
    </html>
    
    EOD;
    		header('HTTP/1.1 302 Moved');
    		header('Content-Type: text/html');
    		header('Location: ' . $url);
    		echo $content;
    		exit;
    
    	}

    Is this what I need to change and how to change exactly, since I'm not a developer?

    Thanks!

  2. Kejatz
    Member
    Posted 4 years ago #

    I just need a simple advice to tweak the code. This should be very simple for someone who is a coder. C'mon don't be shy.

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic