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

Posted on 2011-10-04
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 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>
   Options +FollowSymLinks
   Options +Indexes
ServerAlias *               
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 to deliver the file:

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

    Accepted Solution

    Same idea as your example:

    RewriteRule ^/?$ [R]

    Open in new window


    Author Closing Comment

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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    External Wordpress Site loads very slow 1 196
    Prevent SQL Injection 4 87
    Internal wordpress pages 404 5 33
    Problem to go to page 12 57
    Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
    Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now