如何使用htaccess将url重定向到404页面?

When i am hitting https://mobilecoderz.com/contactffdd then it is returning 404 error page.

Which is absolutely working fine.

When i am hitting https://mobilecoderz.com/contact then it is returning Contact page.

Which is absolutely working fine.

But when i am hitting https://mobilecoderz.com/contact/adfadf then it is also returning contact page.

But it should return 404 error page. How can i achieve this using htaccess?

You can use these 2 lines at the top of your .htaccess:

DirectoryIndex index.html
ErrorDocument 404 http://yoururl

DirectoryIndex will make yoururl load yoururl/index.html by default and use of http:// in ErrorDocument will make it redirect to new URL.

OR

RedirectMatch 404 ^/abc/.*$

OR

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subfolder/404.php [L]