From 4364a77058ea4c30d0882a959fb765bbf599855e Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Mon, 1 Mar 2004 22:16:39 +0000 Subject: [PATCH] allow caching for permanent redirects --- includes/OutputPage.php | 19 ++++++++++++++----- index.php | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 933b8095b7..0e028cb86a 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -36,7 +36,7 @@ class OutputPage { function addHeader( $name, $val ) { array_push( $this->mHeaders, "$name: $val" ) ; } function addCookie( $name, $val ) { array_push( $this->mCookies, array( $name, $val ) ); } - function redirect( $url ) { $this->mRedirect = $url; } + function redirect( $url, $responsecode = '302' ) { $this->mRedirect = $url; $this->mRedirectCode = $responsecode; } # To add an http-equiv meta tag, precede the name with "http:" function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); } @@ -236,10 +236,6 @@ class OutputPage { $sk = $wgUser->getSkin(); - $this->sendCacheControl(); - - header( "Content-type: text/html; charset={$wgOutputEncoding}" ); - header( "Content-language: {$wgLanguageCode}" ); if ( "" != $this->mRedirect ) { if( substr( $this->mRedirect, 0, 4 ) != "http" ) { @@ -247,9 +243,22 @@ class OutputPage { global $wgServer; $this->mRedirect = $wgServer . $this->mRedirect; } + if( $this->mRdirectCode != '302') { + header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently"); + $this->mLastModified = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix( + max( $timestamp, $wgUser->mTouched ) ) ) . " GMT"; + } + + $this->sendCacheControl(); + header( "Location: {$this->mRedirect}" ); return; } + + $this->sendCacheControl(); + + header( "Content-type: text/html; charset={$wgOutputEncoding}" ); + header( "Content-language: {$wgLanguageCode}" ); $exp = time() + $wgCookieExpiration; foreach( $this->mCookies as $name => $val ) { diff --git a/index.php b/index.php index a8b400954e..61220b18ed 100644 --- a/index.php +++ b/index.php @@ -56,8 +56,8 @@ if ( "" != $search ) { $wgTitle = Title::newFromText( wfMsg( "badtitle" ) ); $wgOut->errorpage( "badtitle", "badtitletext" ); } else if ( ( $action == "view" ) && $wgTitle->getPrefixedDBKey() != $title ) { - /* redirect to canonical url */ - $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ) ); + /* redirect to canonical url, make it a 301 to allow caching */ + $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ), '301'); } else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) { wfSpecialPage(); } else { -- 2.20.1