i've been trying to produce a rule for dynamic sub-domain names and attempted many rules distributed by other customers. I can use dynamic sub-domain names and they're working fine now.

My sub-domain structure is sub1.sub2.domain.com

Now i would like that after a person would go to sub1.sub2.domain.com then your default page should be code.php and never index.php

Also in address bar only sub1.sub2.domain.com ought to be visible and never sub1.sub2.domain.com/code.php

Also i must use two level sub-domain names not single sub.domain.com

I simply need assistance in creating the rewrite rule which shows code.php when user accesses sub1.sub2.domain.com


You can test this inshtaccess

# Provide Specific Index Page (Set the default handler)
DirectoryIndex code.php

Edit: Inside your index.php page, before your HTML try something similar to this:

if($_SERVER['SERVER_NAME'] == 'example.com' || $_SERVER['SERVER_NAME'] == 'www.example.com'){
     header('Location: /index.php');
     header('Location: /code.php');

This will consider the server title, including sub-domain and exercise things to use after that from memory.