you are still linking to the URL that contains /_?
... yes but whenever user tries to go to link onclick event ,in new tab he see the _/ in it
Regardless of whether we implement a redirect in .htaccess to "fix" this, you do still need to physically remove the /_ part from the URLs in the HTML source that the users click on. Otherwise, they are not "hidden" from the user (they can see them on the page and in the browser's status bar). Redirecting these URLs will potentially double the number of requests hitting your server and potentially slow the users' experience.
... i dont want to spam my main public_html
Not sure exactly what you mean by "spam", but making the URL appear to be (virtually) in the main directory is really the same as actually being in the main directory - as far as users and search engines are concerned. As far as the local filesystem goes, you still need to avoid conflicts in the same way.
a random folder with index.php inside it it's like this we.xyz.com/_/randomfolder/index.php
In that case, you should be rewriting directly to index.php, not the directory - which would otherwise require mod_dir to issue an internal subrequest for index.php. Also, if you omit the trailing slash then mod_dir would issue an external redirect - which would be undesirable.
Assumptions:
randomfolder can consist of the following characters only: a-z, A-Z, 0-9, _ (underscore), - (hyphen) and . (dot). I've only included the dot, as you appear to have included this in your regex, but otherwise you wouldn't necessarily except directories to contain dots. And omitting the dot would simplify the conditions (since you wouldn't need to check that the request does not match a file).
A request of the form /_/<randomfolder/<anything> strips the trailing /<anything> from the request. And redirects to /<randomfolder> (no trailing slash).
Only requests of the form /<randomfolder> (with or without a trailing slash) are rewritten to /_/<randomfolder>/index.php. We do not currently check that the destination file exists before rewriting (it would result in a 404 either way).
Try the following:
# Redirect requests to remove "/_" from the URL
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^_/([\w.-]+) /$1 [R=302,L]
# Internally rewrite from "/<folder>" to "/_/<folder>/"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w.-]+)/?$ /_/$1/index.php [L]