• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

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

Hi,

I am successfully making the following redirection.  The URL:
something.MyDomain.com
delivers the index.html file that resides on my server here:
/data/www/MyDomain/root/something/index.html

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
something.MyDomain.com
redirect NOT to a subdirectory, but rather to a file in the root directory.  I'd like
something.MyDomain.com to deliver the file:
/data/www/MyDomain/root/something.html

Can this be done?  I can't quite figure it out.
Thanks,
--Steve D.
0
StevenMiles
Asked:
StevenMiles
1 Solution
 
Steve BinkCommented:
Same idea as your example:

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

Open in new window

0
 
StevenMilesAuthor Commented:
Perfect.  Yup, just for some reason couldn't get that last step myself.  Thanks mucho.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now