enables to have specific HTTP status codes on a sys_domain record when doing a redire...
authorErnesto Baschny <ernst@cron-it.de>
Tue, 14 Oct 2008 12:52:45 +0000 (12:52 +0000)
committerErnesto Baschny <ernst@cron-it.de>
Tue, 14 Oct 2008 12:52:45 +0000 (12:52 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4310 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_page.php
typo3/sysext/cms/ext_tables.sql
typo3/sysext/cms/locallang_tca.xml
typo3/sysext/cms/tbl_cms.php

index 80dc91b..d85b053 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-10-14  Ernesto Baschny  <ernst@cron-it.de>
+
+       * Added feature #9400: enables to have specific HTTP status codes on a sys_domain record when doing a redirect (new field sys_domain.redirectHttpStatusCode)
+
 2008-10-14  Dmitry Dulepov  <dmitry@typo3.org>
 
        * Fixed bug #9523: class.t3lib_htmlmail.php produces null headers in HTML messages
index 598e4f6..516bf11 100755 (executable)
@@ -504,7 +504,7 @@ class t3lib_pageSelect {
                $domain = ereg_replace('\/*$','',$domain);
 
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                                       'pages.uid,sys_domain.redirectTo,sys_domain.prepend_params',
+                                       'pages.uid,sys_domain.redirectTo,sys_domain.redirectHttpStatusCode,sys_domain.prepend_params',
                                        'pages,sys_domain',
                                        'pages.uid=sys_domain.pid
                                                AND sys_domain.hidden=0
@@ -518,14 +518,19 @@ class t3lib_pageSelect {
                $GLOBALS['TYPO3_DB']->sql_free_result($res);
                if ($row)       {
                        if ($row['redirectTo']) {
-                               $rURL = $row['redirectTo'];
+                               $redirectUrl = $row['redirectTo'];
                                if ($row['prepend_params'])     {
-                                       $rURL = ereg_replace('\/$','',$rURL);
+                                       $redirectUrl = ereg_replace('\/$', '', $redirectUrl);
                                        $prependStr = ereg_replace('^\/','',substr($request_uri,strlen($path)));
-                                       $rURL.= '/'.$prependStr;
+                                       $redirectUrl .= '/' . $prependStr;
+                               }
+
+                               $statusCode = intval($row['redirectHttpStatusCode']);
+                               if ($statusCode && defined('t3lib_div::HTTP_STATUS_' . $statusCode)) {
+                                       t3lib_div::redirect($redirectUrl, constant('t3lib_div::HTTP_STATUS_' . $statusCode));
+                               } else {
+                                       t3lib_div::redirect($redirectUrl, 't3lib_div::HTTP_STATUS_301');
                                }
-                               Header('HTTP/1.1 301 Moved Permanently');
-                               Header('Location: '.t3lib_div::locationHeaderUrl($rURL));
                                exit;
                        } else {
                                return $row['uid'];
index 25447a2..648d3f9 100755 (executable)
@@ -246,6 +246,7 @@ CREATE TABLE sys_domain (
   hidden tinyint(4) unsigned DEFAULT '0' NOT NULL,
   domainName varchar(80) DEFAULT '' NOT NULL,
   redirectTo varchar(120) DEFAULT '' NOT NULL,
+  redirectHttpStatusCode int(4) unsigned DEFAULT '301' NOT NULL,
   sorting int(10) unsigned DEFAULT '0' NOT NULL,
   prepend_params int(10) DEFAULT '0' NOT NULL,
 
index cd36b8e..430bce5 100755 (executable)
                        <label index="sys_domain">Domain</label>
                        <label index="sys_domain.domainName">Domain:</label>
                        <label index="sys_domain.redirectTo">Redirect to:</label>
+                       <label index="sys_domain.redirectHttpStatusCode">HTTP Status Code for the Redirect:</label>
+                       <label index="sys_domain.redirectHttpStatusCode.301">Moved permanently (301)</label>
+                       <label index="sys_domain.redirectHttpStatusCode.302">Found (302)</label>
+                       <label index="sys_domain.redirectHttpStatusCode.303">See other (303)</label>
+                       <label index="sys_domain.redirectHttpStatusCode.307">Moved temporarily (307)</label>
                        <label index="sys_domain.prepend_params">Transfer parameters to Redirect URL:</label>
                        <label index="sys_template">Template</label>
                        <label index="sys_template.title">Template title:</label>
index 784a307..885b931 100755 (executable)
@@ -412,6 +412,21 @@ $TCA['sys_domain'] = array(
                                'softref' => 'substitute'
                        ),
                ),
+               'redirectHttpStatusCode' => array(
+                       'exclude' => 1,
+                       'label' => 'LLL:EXT:cms/locallang_tca.xml:sys_domain.redirectHttpStatusCode',
+                       'config' => array(
+                               'type' => 'select',
+                               'items' => array(
+                                       array('LLL:EXT:cms/locallang_tca.xml:sys_domain.redirectHttpStatusCode.301', '301'),
+                                       array('LLL:EXT:cms/locallang_tca.xml:sys_domain.redirectHttpStatusCode.302', '302'),
+                                       array('LLL:EXT:cms/locallang_tca.xml:sys_domain.redirectHttpStatusCode.303', '303'),
+                                       array('LLL:EXT:cms/locallang_tca.xml:sys_domain.redirectHttpStatusCode.307', '307'),
+                               ),
+                               'size' => 1,
+                               'maxitems' => 1,
+                       ),
+               ),
                'hidden' => array(
                        'label' => 'LLL:EXT:lang/locallang_general.php:LGL.disable',
                        'exclude' => 1,
@@ -433,7 +448,7 @@ $TCA['sys_domain'] = array(
                '1' => array('showitem' => 'hidden;;;;1-1-1,domainName;;1;;3-3-3,prepend_params')
        ),
        'palettes' => array(
-               '1' => array('showitem' => 'redirectTo')
+               '1' => array('showitem' => 'redirectTo, redirectHttpStatusCode')
        )
 );