If you're doing it with a .htaccess file, which I'm guessing from the tag on your question, it would look something like this (replace subfolder with you actual subfolder name and example with your actual site name):
RewriteEngine on
RewriteBase /
# Rule to NOT rewrite requests that already have the /subfolder/ in them
RewriteCond %{REQUEST_URI} !^/subfolder/
# example is the URL without the .com, so replace it with your actual domain without the top level domain
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Rewrite all those URLs to put subfolder between the site path and the root site
RewriteRule ^(.*)$ /subfolder/$1 [L]
The file has to be placed in the webroot directory and your webserver has to configured to accept .htaccess files (on apache that would be "AllowOverride All" for your website's root directory).
But if you are in control of the webserver (nginx/apache/whatever), it's better to configure it on the webserver level, the .htaccess approach should only be taken if it's just webspace from a webhoster or when you don't have access to the webserver configuration:
You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.
https://httpd.apache.org/docs/2.4/howto/htaccess.html