Giter Club home page Giter Club logo

justincase's Introduction

TYPO3 Extension "just in case" - No matter what case your URL is, we'll hit it.

When your marketing team has accidentally pushed a campaign with mixed case URLs, they should not run into 404s.

This TYPO3 extension solves your pain - just in case.

What does it do?

By default, TYPO3 v9 is strict when you're actual page is called https://b13.com/lets-connect/ but your marketing dudes name it https://b13.com/Lets-Connect/. TYPO3 v9 saves URLs as lower-case by default.

A simple PSR-15 based middleware transforms your incoming URL into lower-case and you should be fine, as both URLs would work for the users.

Installation

Use it via composer req b13/justincase or install the Extension justincase from the TYPO3 Extension Repository.

justincase requires TYPO3 v9.5.0 or later.

Configuration

As a web developer, sometimes the team wants a 307 redirect, and sometimes to just work as everything would be lower-case.

justincase does the latter ("just pretend it works") and receives the URL, processes the URL further by default, however you can configure the extension on a per-site basis to do redirects instead, by modifying the Languages array of the site configuration yaml:

languages:
    -
    title: English
    ...
    redirectOnUpperCase: true
    # in case you want to use a status code, other than 307
    redirectStatusCode: 303

If you wish to enable redirect for all languages, add these lines at the bottom of the site configuration yaml instead:

settings:
    redirectOnUpperCase: true
    # in case you want to use a status code, other than 307
    redirectStatusCode: 303

Please note that this option only works for GET or HEAD requests.

Caveats

If specific route enhancers check on camel-case (e.g. {order}/paymentForm/) this might lead to unexpected behaviours and 404 pages.

License

As TYPO3 Core, justincase is licensed under GPL2 or later. See the LICENSE file for more details.

Background, Credits & Further Maintenance

This extension was created as a show-case on what you can do with middlewares for TYPO3 v9 and customize so many things. See https://forge.typo3.org/issues/87544 for the initial request.

TYPO3 community often requests functionality, which can be put in small and efficient extensions, and justincase does exactly that, without having to burden everything into TYPO3 Core.

justincase was initially created by Daniel Goerz and Benni Mack for b13, Stuttgart, with the nice support from Matthias Stegmann for providing the extension name.

Find more TYPO3 extensions we have developed that help us deliver value in client projects. As part of the way we work, we focus on testing and best practices to ensure long-term performance, reliability, and results in all our code.

justincase's People

Contributors

b13-michaelsemle avatar bmack avatar davidsteeb avatar infabo avatar nimmermaer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

justincase's Issues

TypeError when no SiteLanguage was resolved

If the router did not resolve a SiteLanguage for the current Site, the call of $site->getRouter()->matchRequest($request, $previousResult); in \B13\JustInCase\Middleware\LowerCaseUri::process will cause a TypeError in \TYPO3\CMS\Core\Routing\PageRouter::matchRequest in TYPO3 11.5.30.

How to reproduce

Have a site with one or more langage, but no language has an empty, or just a slash, as slug as entry. Similar to this site config:

base: 'https://my.site/'

languages:
  - title: English
    languageId: 0
    base: /en
    # ....
  - title: Italian
    languageId: 1
    base: /it
    # ...

Now call an URL without any of those prefixes, eg. https://my.site/not/existing/site.

The expected behaviour would be a 404 page, instead a 503 error and message is shown.

Possible fix

When changing the lines

$site->getRouter()->matchRequest($request, $previousResult);
return $handler->handle($request);

in \B13\JustInCase\Middleware\LowerCaseUri::process to

if ($previousResult->getLanguage()) {
    $site->getRouter()->matchRequest($request, $previousResult);
}

return $handler->handle($request);

It works as expected. Also the lowercase redirects work for URLs with a prefix.

justincase breaks TYPO3 10.4.36

Hi there,

when updating to the latest TYPO3 10.4.36 version (for obvious security reasons), one of our customers site broke.

This is our site configuration. The expected behaviour (as it was before and how it works if we disable justincase) is that on access to / you'll get redirected to /en/:

sites/site/config.yaml
base: '/'
disableStaticFileCache: false
errorHandling:
 -
   errorCode: '404'
   errorHandler: Page
   errorContentSource: 't3://page?uid=87'
languages:
 -
   languageId: '0'
   title: English
   navigationTitle: en
   base: /en/
   locale: en_GB.UTF-8
   iso-639-1: en
   hreflang: en-GB
   direction: ltr
   typo3Language: default
   flag: en-us-gb
   enabled: true
   websiteTitle: ''
   fallbackType: strict
   fallbacks: ''
 -
   languageId: '1'
   title: Deutsch
   navigationTitle: de
   base: /de/
   locale: de_CH.UTF-8
   iso-639-1: de
   hreflang: de-CH
   direction: ltr
   typo3Language: de
   flag: de
   enabled: true
   websiteTitle: ''
   fallbackType: strict
   fallbacks: ''
 -
   languageId: '2'
   title: Francais
   navigationTitle: fr
   base: /fr/
   locale: fr_CH.UTF-8
   iso-639-1: fr
   hreflang: fr-CH
   direction: ltr
   typo3Language: fr
   flag: fr
   enabled: true
   websiteTitle: ''
   fallbackType: strict
   fallbacks: ''
rootPageId: 1
websiteTitle: 'Customers page'
imports:
 -
   resource: ../global/route-enhancers.yaml
sites/globals/route-enhancers.yaml
routeEnhancers:
  PageTypeSuffix:
    type: PageType
    default: ''
    index: ''
    map:
      .html: 0
      rss.xml: 10
      sitemap.xml: 1533906435
What I've discovered so far:
  1. Something has changed in TYPO3 10.4.36 (or probably earlier => I was able to confirm that this has to with the latest change in TYPO3 10.4.36) that disallows "null" als LanguageObject (or maybe this was already the case before but the way the information is usually gathered changed).
  2. Nothing more... :-/

I don't like to create tickets without having an idea on how to fix this but I was sadly unable to find the reason why this happens :-( I hope you are luckier.

Best Regards
Tizian

Undefined array key "settings"

A PHP Warning is generated on every page if you don't have a "settings" section in your site config (PHP 8.1). To fix, change line 45 of LowerCaseUri.php from:

$doRedirect = (bool)$site->getConfiguration()['settings']['redirectOnUpperCase'] ?? false;

to

$doRedirect = (bool)($site->getConfiguration()['settings']['redirectOnUpperCase'] ?? false);

Redirects do not work, if they are not written in lowercase

As your middleware sets the incoming urls to lowercase, all sys_redirect-records do not match, if they are not written in lowercase.

Perhaps you can add a notice for this to your Readme.

This query helps solving this topic for existing records:
UPDATE sys_redirect set source_path = LOWER(source_path);

The middleware breaks secure_downloads links

Hi there,
I found out the hard way that justincase breaks the links generated by ext:secure_downloads

Thanks to the other issue, i hotfixed it like this:
insert here src/Middleware/LowerCaseUri.php at line 36

        // TODO: if securedl is installed, get securedl prefix
	    if (str_contains($path, 'securedl')) {
		    return $handler->handle($request);
	    }

ext:justincase causes a problem opposite to it's claim

No matter what case your URL is, we'll hit it.

I have encountered a situation, where ext:justincase makes the opposite: it makes originally matching/working URLs suddenly not matching anymore.

Something is mentioned in the README already - but is misleading:

Caveats
If specific route enhancers check on camel-case (e.g. {order}/paymentForm/) this might lead to unexpected behaviours and 404 pages.

It fails even if the route-enhancer routePath casing is correct. Any route-argument which is not fully lowercase makes it break (404 exception).

See for more information: https://forge.typo3.org/issues/92565

Error with Typo3 11 and PHP 8

Hi,

Line 45 in /typo3conf/ext/justincase/src/Middleware/LowerCaseUri.php generates a PHP Warning in Typo3.11.5.16 and PHP 8: Undefined array key.
$doRedirect = (bool)$site->getConfiguration()['settings']['redirectOnUpperCase'] ?? false;
should be:
$doRedirect = (bool)($site->getConfiguration()['settings']['redirectOnUpperCase'] ?? false);

Kind regards

Tomas

The middleware is processed for files too

Maybe its something not for this; but I had to manually do this in my own environment and wanted to mention it here:

I have a middleware handling 'secured' files to find the files and serve the file to the browser. As this is processed through middleware the justincase extension lowercased the filepath too; resolving into unknown files.

I fixed this with the following code before the lowerstring check is executed:

       // Safe check that no direct file is requested
        $absolutePath = GeneralUtility::sanitizeLocalUrl(Environment::getPublicPath() . $path);
        if (file_exists($absolutePath)) {
            return $handler->handle($request);
        }

Do you think this should be added for possible other conflicts too?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.