.htaccess — Trailing slash and characters after file extension

I’ve got some weird usability warnings popping up in my search console for pages which don’t actually exist on my site. It looks like someone is creating 100’s of malformed links to my pages.

Here’s the problem.

Say I have https://example.com/pagename.html

Someone is creating hundreds of links with random text after the filetype like this: https://example.com/pagename.html/randomtext

Strangely, with that malformed URL, part of the page renders, but renders with broken styling for some reason. (Triggering search console warnings for every one of those "pages"). I’m not really sure how or why these broken URLs are rendering at all. My understanding is that this should return a 404 error. But it doesn’t.

So…

I’m trying to solve the problem with .htaccess like this:

RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$   /$  1 [L,R=301] 

That sort of works. It removes the trailing slash from https://example.com/pagename.html/ but it doesn’t fix https://example.com/pagename.html/randomchars

How do I get it to ignore all characters following the file type? (except standard GET strings starting with a ?)

Thanks in advance.