mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: Ticket #2382 - Merged patch changing 302 for /home to 301
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@53177 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
3f50c7a477
commit
4a5443c5da
@ -88,7 +88,7 @@ class ContentController extends Controller {
|
||||
unset($getVars['url']);
|
||||
if($getVars) $url = "?" . http_build_query($getVars);
|
||||
else $url = "";
|
||||
Director::redirect($url);
|
||||
Director::redirect($url, 301);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -509,7 +509,7 @@ class Controller extends ViewableData {
|
||||
* Redirct to the given URL.
|
||||
* It is generally recommended to call Director::redirect() rather than calling this function directly.
|
||||
*/
|
||||
function redirect($url) {
|
||||
function redirect($url, $code=302) {
|
||||
if($this->response->getHeader('Location')) {
|
||||
user_error("Already directed to " . $this->response->getHeader('Location') . "; now trying to direct to $url", E_USER_ERROR);
|
||||
}
|
||||
@ -519,7 +519,7 @@ class Controller extends ViewableData {
|
||||
$url = Director::baseURL() . $url;
|
||||
}
|
||||
|
||||
$this->response->redirect($url);
|
||||
$this->response->redirect($url, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -285,8 +285,8 @@ class Director {
|
||||
* - or it can be a URL relative to the "site base"
|
||||
* - if it is just a word without an slashes, then it redirects to another action on the current controller.
|
||||
*/
|
||||
static function redirect($url) {
|
||||
Controller::curr()->redirect($url);
|
||||
static function redirect($url, $code=302) {
|
||||
Controller::curr()->redirect($url, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,6 +53,15 @@ class HTTPResponse extends Object {
|
||||
505 => 'HTTP Version Not Supported',
|
||||
);
|
||||
|
||||
protected static $redirect_codes = array(
|
||||
301,
|
||||
302,
|
||||
303,
|
||||
304,
|
||||
305,
|
||||
307
|
||||
);
|
||||
|
||||
protected $statusCode = 200;
|
||||
protected $headers = array();
|
||||
protected $body = null;
|
||||
@ -91,8 +100,9 @@ class HTTPResponse extends Object {
|
||||
}
|
||||
}
|
||||
|
||||
function redirect($dest) {
|
||||
$this->statusCode = 302;
|
||||
function redirect($dest, $code=302) {
|
||||
if(!in_array($code, self::$redirect_codes)) $code = 302;
|
||||
$this->statusCode = $code;
|
||||
$this->headers['Location'] = $dest;
|
||||
}
|
||||
|
||||
@ -100,7 +110,7 @@ class HTTPResponse extends Object {
|
||||
* Send this HTTPReponse to the browser
|
||||
*/
|
||||
function output() {
|
||||
if($this->statusCode == 302 && headers_sent($file, $line)) {
|
||||
if(in_array($this->statusCode, self::$redirect_codes) && headers_sent($file, $line)) {
|
||||
$url = $this->headers['Location'];
|
||||
echo
|
||||
"<p>Redirecting to <a href=\"$url\" title=\"Please click this link if your browser does not redirect you\">$url... (output started on $file, line $line)</a></p>
|
||||
|
Loading…
Reference in New Issue
Block a user