Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been working on this problem for a 3 solid days and posted on several forums with no leads.


When a user types in I want it to stay that way in the URL window.

The real location of these files is

I know that this is possible using a DNS A record (which I have done) and a .htaccess rule.

This is my .htaccess rule at the moment

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.domain\.com$ [NC]
RewriteRule !^([a-z0-9-]+)($|/) /apps/%2%{REQUEST_URI} [PT,L]

Ok, this almost works.

Typing in is reading from

BUT something is going horribly wrong.

Visiting (AKA works fine

Visiting (AKA returns a 404

Looking at the Cpanel Error log shows this

[Thu Nov 18 20:48:50 2010] [error] [client ***.**.***.***] File does not exist: /home/domain/public_html/images, referer:

So it appears to be correctly rewriting on a first directory basis but anything lower then that gets sent back to public_html root

All help and advice would be greatly appreciated



PS. I had to remove the proper hyperlink formatting as I am a new user.

share|improve this question
up vote 2 down vote accepted

Correct me if I'm wrong, but the rewrite rule you have:

RewriteRule !^([a-z0-9-]+)($|/) /apps/%2%{REQUEST_URI} [PT,L]

says: rewrite only if ^([a-z0-9-]+)($|/) does not match. When your URL path is /anyfolder/image.jpg, the above will match (^anyfolder/), thus rewrite rule will not be run, so you will basically continue to

The following SO question has a similar requirement:

In his answer, glavić gives the response that should work, also gives this link:

Try it out, it should work OK.

share|improve this answer
Thanks!!! This worked really well. It's perfect. Have a great weekend! – Tim Nov 20 '10 at 8:11
Glad to help Tim! – Nov 20 '10 at 13:40
Hey, sorry to bother you. If you have time I have posted another question you may be able to help with as it is sort of an extension to this one.… – Tim Nov 23 '10 at 23:47

Can you edit the httpd.conf? It seems much more straightforward to use dynamic virtual hosts. Check out and

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.