typo3typo3-6.2.xrealurl

Realurl rewrite without extension


I'm using a website running TYPO3 6.2 with Realurl extension.

In the tree I created a "Cars" page with ID #66 and with "cars/" as speaking url path segment. My page is now available with https://www.mywebsite.com/cars/. Cool.

What I need, if going on https://www.mywebsite.com/cars/audi, is to retrieve the audi as a GET variable (GP:car_brand) in Typoscript but current Typo3 default behavior is to search for a audi page below the existing cars page... and then display a 404 error.

What I have already tried:

1/ Adding a RewriteRule inside the .htaccess: RewriteRule ^cars/(.*)$ /index.php?id=66&car_brand=/$1 [P]. It works but the user is redirected to https://www.mywebsite.com/cars/?car_brand=audi, and we really need to keep the cars/audi/ URL scheme which is more SEO compliant / user friendly.

2/ Adding custom configuration inside my realurl_conf.php postVarSets but realurl is very hard to understand and I don't have the technical skills to deal with it:

<?php

'postVarSets' => [
    66 => array(
        array(
            'GETvar' => 'car_brand',
            'valueMap' => array(
                'no-comments' => 1
            ),
        

    'noMatch' => 'bypass',
        )
    ),

    ...

]

Solution

  • To add a userFunc, have a look there :

    https://github.com/dmitryd/typo3-realurl/wiki/Configuration-reference#userfunc

    In realurl_conf.php :

    'postVarSets' => array(
        '66' => array(
            'brand' => array(
                array(
                    'GETvar' => 'car_brand',
                    'userFunc' => 'Vendor\Userfuncs\Example->myExampleFunction',
                    'noMatch' => 'bypass',
                ),
            ),
        ),
    ),
    

    In your class :

    namespace Vendor\Userfuncs;
    class Example {
        function myExampleFunction($params, $ref) {
            if ($params["decodeAlias"]) {
                return ($decodedAlias));
            } else {
                return ($encodedAlias));
            }
        }
    }