views:

65

answers:

1

I apologize in advance if I missed someone cover this already; I tried to see if someone had my own .htaccess dilemma:

I currently have the following website: www.example.com

I want to set it up like the following: somewebsite.example.com

And have the subdomain "somewebsite" point to a subfolder on my root. If that subdomain is not available, return them to an error.html in the root folder.

Example:

/
error.html
/img
/websites
    /somewebsite
        index.html

Here is my .htaccess for the root folder that I am working with:

RewriteEngine on
Options +FollowSymlinks
RewriteBase /

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^somewebsite\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !somewebsite/ !-d
RewriteRule ^/(.*)$ http://somewebsite.example.com/$1 [L,R=301]

I'm not amazing with RegExp or .htaccess file, but what am I missing to accomplish my goal?

A: 

Try this rule:

RewriteCond %{HTTP_HOST} ^([^./]+)\.example\.com$
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule ^ %{DOCUMENT_ROOT}/%1%{REQUEST_URI} [L]

This rule tests if foobar.example.com with an arbitrary foobar can be mapped to an existing directory located in the document root directory.

Gumbo
Thanks Gumbo for your help; let me clarify the scenario:I want a visitor to come to a page http://chris.domain.comwhere "chris" is a subfolder of a "websites" folder that resides in the server root (root -> websites -> chris).so I am going to have in the server root, an .htaccess file that redirects that.in the chris folder, I want an .htaccess file that I can tell it to be http://www.chris.com or http://chris.com (when I write to it in php)Hope this helps clarify the scenario. THanks!
Chris
@Chris: Then just need to alter the path like: `%{DOCUMENT_ROOT}/websites/%1…`
Gumbo