Redirect multiple subdomains to different specific index.php files

Viewed 28

i'm hosting different sites using the same domain. I would like to redirect each subdomain to different "index.php" Here is an example from what i want to do:

subdomain1.mydomain.com --> http://subdomain1.mydomain.com/subdomain1/index.php
subdomain2.mydomain.com --> http://subdomain2.mydomain.com/subdomain1/index.php

This is my file structure:

/var/www/
    '-- html
        |-- site1
            '-- index.php
        '-- site2
            '-- index.php

I've been trying to achiev this by using the ".htaccess" file, but i'm not getting there.

I know .htaccess isn't the only workaround. I may use javascrip or PHP script

1 Answers

you can use this code:

site1-->index.php code:

<?php
header('Location: http://subdomain2.mydomain.com/subdomain1/index.php');
?>

site2-->index.php code:

<?php
header('Location: http://subdomain1.mydomain.com/subdomain1/index.php');
?>
Related