A: 

Why not try using a Redirect Directive from mod_alias?

Myles
I dont know about redirect directive - does it actually redirect og does it work like rewrite? I would like to keep the url (sub.mydomain.com) in the browser address bar.
Kantahara
Ah, it actually redirects. Another option then is to use mod_alias and just create an alias for your subdomain to the main folder.
Myles
A: 

I must admit that I did not fully understand your question. Do you want to redirect everything from sub.mydomain.com/whatever to mydomain.com/whatever? In that case, the following (put in the config file of your sub.mydomain.com) might work:

    RewriteEngine On
    RewriteRule ^/(.*)$ http://mydomain.com/$1 [R,L]

It redirects on the client side, meaning that the user will see mydomain.com/sub in the browser.


EDIT: I think I understand your question now. Yes, it's a permissions issue: If the DocumentRoot of your web site is /whatever/sub, then you cannot just access /whatever by adding "/.." to the URL. I hope you understand that this is a good thing. :-) mod_rewrite just changes the URL, so it cannot do that either.

So, to solve your problem, you need to either change the DocumentRoot of sub.mydomain.com or create a symlink that allows you to access the required directory (e.g. /whatever/sub/redir-target -> /whatever). Be careful with the symlink option, though, since it will create valid directories of infinite length on your file system (/whatever/sub/redir-target/sub/redir-target/...) and some scripts cannot cope with that.


EDIT2: Instead of a symlink, you might want to create an alias, e.g., something like this:

Alias /redir-target /home/web/webuser

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/redir-target/.*$
RewriteRule ^/(.*)$ /redir-target/$1

Still, I think the easiest solution is to change the DocumentRoot...

Heinzi
I would like to keep the url (sub.mydomain.com). When including http it will actually redirect and not keeping the url in the browser window.
Kantahara
A: 

It's difficult to provide a definitive answer without knowing more about your server configuration.

The following might work and is at the very least a decent starting point:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.mydomain\.com 
RewriteRule (.*) /$1 [L]

Ideally that would go in your httpd.conf, but might work from a .htaccess file (again, more information about how your subdomains are setup would be helpful).

gavinjames