Simple page URL rewrite with add_rewrite_rule()

The second argument of add_rewrite_rule is not a path, it the query string you want WordPress executes. This should work for example.com/sub-folder/thepage/ (change page_id with ID of your page):

add_rewrite_rule('thepage/', 'index.php?page_id=12');

or with page slug:

add_rewrite_rule('thepage/', 'index.php?pagename=thepage');

As you have WordPress in a subdirectory and you want to rip out the directoy name, you have to properly cofigure WordPress in sudirectory.

If you want all WordPress URLs in the format example.com/sub-folder/ and only rip out “sub-folder” for “thepage” you have to configure the rewrite rule in the .htaccess file on the root directory, not in WordPress:

RewriteRule ^thepage(/)?$ sub-folder/index.php?page_id=12 [L]