Add the following code at the top of your .htaccess file:
# BEGIN redirect to homepage RewriteEngine on RewriteCond %{REQUEST_URI} !^/$ RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js|php)$ RewriteCond %{REQUEST_URI} !^/wp-admin [NC] RewriteRule .* / [L,R=301] #END redirect to homepage
Source: https://eugenoprea.com/code-snippets/wordpress-redirect-all-urls-to-homepage/