I've got a hosting that is shared with one domain and something sub-domain (for mobile and clients). Each domain and sub-domain names has different default index pages. The webhost explained to place my way through my .htaccess file since i have don't have the httpd.conf.

What I wish to do is:

  1. If your user would go to domain1.com the DirectoryIndex ought to be: index.html
  2. If your user would go to mobile.domain1.com the DirectoryIndex ought to be: mobile-index.html
  3. If your user would go to publish.domain1.com the DirectoryIndex ought to be: post.php
  4. If your user would go to election.domain1.com the DirectoryIndex ought to be: vote.php

Edit: Additionally, basically visit domain1.com/page/ the DirectoryIndex ought to be: index.html. Basically visit mobile.domain1.com/page/ the DirectoryIndex ought to be: mobile-index.html

So what can I place in my .htaccess file to be able to alter the DirectoryIndex for every sub-domain?

Thanks very mich

<IfDefine> doesn't work like this. <IfDefine> only runs when apache begins. You need to opt for a mod_rewrite solution. view @tzakrajs answer.

This can be used inside your .htaccess file:

SetEnvIf Host ^www\. page=www
SetEnvIf Host ^mobile\. page=mobile
rewriterule ^.*$ test.php?subdomain=%{ENV:page} [QSA,L]

Just configure all of your sub-domain using SetEnvIf after which simply allow the PHP do its miracle.

Do this:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain1.com$
RewriteRule ^.*/$ index.html [R=302,L]
RewriteCond %{HTTP_HOST} ^mobile.domain1.com$
RewriteRule ^.*/$ mobile-index.html [R=302,L]
RewriteCond %{HTTP_HOST} ^post.domain1.com$
RewriteRule ^.*/$ post.php [R=302,L]
RewriteCond %{HTTP_HOST} ^vote.domain1.com$
RewriteRule ^.*/$ vote.php [R=302,L]