How to remove the trailing slash from url’s at RealURL + typo3


I got my grade for some time racking their brains on how to the trailing slash, the RealURL automatically adds that slash if “defaultToHTMLsuffixOnPrev” is not set

http://www.example.com/artical/ -> http://www.example.com/artical

Here we have two solution for remove the trailing slash from url.

The following solution is extremely simple and banal, does not require any manipulation of the core files – only a “value” is entered in “defaultToHTMLsuffixOnPrev”.

First Solution

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT'] = array (
    'fileName' => array (
        'defaultToHTMLsuffixOnPrev' => chr(0),
    ),
);

if some time its not workout that time you can use 
'defaultToHTMLsuffixOnPrev' => chr(1),

Second Solution

function user_encodeSpURL_postProc(&$params, &$ref) {
    if ($params['URL'] != '/') {
        $params['URL'] = preg_replace(
            '/\/($|\?|\#)/U',
            '\1',
            $params['URL']
        );
    }
}

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'] = array (
    'EncodeSpURL_postProc' => array ( 'user_encodeSpURL_postProc'),
    '_DEFAULT' => Array (
    'Init' => array (
            // [...]
            'AppendMissingSlash' => 'ifNotFile'
            )
        // [...]
    )
);

URL will look like after applying above script :

www.example.com/artical

Second method may be not work for old version of realurl. so better we use first method

If you need trailing slash from url then simply use 0 in “defaultToHTMLsuffixOnPrev”

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT'] = array (
    'fileName' => array (
        'defaultToHTMLsuffixOnPrev' => 0,
    ),
);

URL will look like after appling above script :

www.example.com/artical/

If you need trailing with .html from url then simply use 1 in “defaultToHTMLsuffixOnPrev”

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT'] = array (
    'fileName' => array (
        'defaultToHTMLsuffixOnPrev' => 1,
    ),
);

URL will look like after appling above script :

www.example.com/artical.html

I hope today i make your day 😉

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s