On my old shared hosting it redirected all www.mydomain.com requests to the cgi script and all did worked fine.
Now i am getting an "Access forbidden!" error because there is no index.html file and it does not redirect anymore.
Now i am unsure if there is some setting on the server i need or is there a trick in the .htaccess to do. All other redirects to subpages work fine and also if i type www.mydomain.com/index.php it works.
In order for mod_rewrite to work in a .htaccess file, several things must happen:
1) the mod_rewrite module must be loaded in the server config (this is true for (*any* rule, .htaccess or not)
2) The 'FileInfo' option for the AllowOverride config option must be in force for the directory your .htaccess file is in
3) The first rewrite line in the .htaccess file SHOULD be 'RewriteEngine on'
You'll need to check your httpd.conf for the first two; note that if you *do* have write access to httpd.conf, that is far and away the preferred place to have your Rewrite lines; the performance hit for using them in .htaccess is significant.
Be advised that that solution will work as long as people don't try and arrive at your site by typing/clicking to "http://www.mydomain.com/index.php"; it will fail the regex match. To account for both of these: RewriteEngine on RewriteRule ^($Žindex.php$) http://www.mydomain.com/cgi-bin/x.cgi [R,L]
(Yes, the 'R' is optional, since you're specifying a target path prefixed with 'http://'; I personally prefer to be explicit about this sort of thing as it makes the rules (slightly) more self-documenting).