Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a project which utilizes wildcard subdomains to allow requests for www.foo.com, api.foo.com, & admin.foo.com to utilize the same document root.

Routing for this project is based initially upon the host.

I need to compose an .htaccess file which will funnel all requests through index.php while preserving the subdomain (to facilitate routing).

So far I have this:

<IfModule mod_rewrite.c>
   Options -MultiViews

   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^ index.php [L]
</IfModule>

That doesn't preserve the subdomain, however, so routing fails.

I am confident that everything else is set up correctly as including index.php in the request, like this:

http:admin.foo.com/index.php/dashboard

routes properly.

share|improve this question
    
What does the "wildcard subdomains" setup look like? Are you at all using virtualhosts, or how is it happening? –  Jenny D Apr 5 '13 at 8:39
    
@JennyD - exactly, via virtual hosts. I've a single virtual host; its servername is a placeholder, its serveralias is *.foo.com, no rewrite rules exist there. –  coderabbi Apr 5 '13 at 17:48
    
What do you actually mean with "does not preserve the subdomain". The "host" header should not be changed, so your index.php should be able to read the HTTP_HOST variable to know which subdomain it was for. –  Krist van Besien Apr 6 '13 at 7:22
    
@KristvanBesien - As in all requests end up at a single subdomain rather than the subdomain for which they were intended - admin.foo.com/login ultimately resolves to www.foo.com/login, for instance. –  coderabbi Apr 7 '13 at 0:53
    
@coderabbi: How is the "routing" in index.php done? Again, your rewriterules don't change the "host" header, so that should be used to offer the correct content, or generate the right links, redirects etc... –  Krist van Besien Apr 7 '13 at 10:09
show 2 more comments

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.