How to rewrite a subdomain to a file rather than a directory

Posted on 2011-10-04
Medium Priority
Last Modified: 2012-05-12

I am successfully making the following redirection.  The URL:
delivers the index.html file that resides on my server here:

Here's how I did it:
I added an A record with a wildcard before MyDomain.com
MyDomain.com is in a VirtualHost container in Apache's httpd.conf (because it's not the main domain that my server serves)

Here are the pertinent lines from httpd.conf:

<VirtualHost My.IP.Add.ress:80>
ServerName www.MyDomain.com
   Options +FollowSymLinks
   Options +Indexes
ServerAlias www.MyDomain.com MyDomain.com *.MyDomain.com               
DirectoryIndex index.html
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.MyDomain\.com
RewriteRule ^(.*) /%1/$1 [L]

What I would LIKE to do is have
redirect NOT to a subdirectory, but rather to a file in the root directory.  I'd like
something.MyDomain.com to deliver the file:

Can this be done?  I can't quite figure it out.
--Steve D.
Question by:StevenMiles
LVL 51

Accepted Solution

Steve Bink earned 2000 total points
ID: 36915918
Same idea as your example:

RewriteRule ^/?$ http://mydomain.com/root/%1.html [R]

Open in new window


Author Closing Comment

ID: 36918666
Perfect.  Yup, just for some reason couldn't get that last step myself.  Thanks mucho.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question