koninklijke-collective / my_redirects

TYPO3 Extension: Redirects management
https://typo3.org/extensions/repository/view/my_redirects
GNU General Public License v2.0
17 stars 20 forks source link

Redirects not working if multiple domains are used #62

Closed aktivwebagentur closed 6 years ago

aktivwebagentur commented 6 years ago

We found that redirects are not working (404 error page) if Typo3 is configured for multiple domains. The realurl config array is then configured per domain as follows

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_ here is the host name _']['pagePath']['rootpage_id']

As a workaround we changed the following method in class \KoninklijkeCollective\MyRedirects\Utility\ConfigurationUtility:

/**
     * @return integer
     */
    public static function getDefaultRootPageId()
    {
        $configuration = static::getConfiguration();
        $host = $_SERVER['SERVER_NAME'];
        if(isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$host])){
            return (int)($configuration['defaultRootPageId'] ?: ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$host]['pagePath']['rootpage_id'] ?: 1));
        }
        return (int)($configuration['defaultRootPageId'] ?: ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']['pagePath']['rootpage_id'] ?: 1));
    }

We propose that this patch should be inserted in the official repository

Kind regards Bernhard Stöcker Aktivweb GmbH

bmoex commented 6 years ago

Hi @aktivwebagentur,

Thank you for your suggestion. You could configure it via: $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['my_redirects']['defaultRootPageId'] where you can define it via the $host.

So in your server configuration;

switch ($_SERVER['SERVER_NAME']) { 
    case 'your-host.com':
        $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['my_redirects']['defaultRootPageId'] = 2314;
        break; 
    default: 
        $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['my_redirects']['defaultRootPageId'] = 1;
        break;
}

There is a high probability that the my_redirects module will be refactored when TYPO3 9.x routing is possible and RealURL will be deprecated.

As of the upcoming refactoring of my_redirects, the domains will be used differently. I will try to fit in a similar solution of this.

Kind regards,

Benjamin Serfhos