Re-direct maindomain.com/maindomain to maindomain.com, is it possible?

Discussion in 'Apache' started by webeducation, Jun 24, 2009.

  1. #1
    /maindomain/ is a folder that contains all the content for maindomain.com. This folders sits inside /public_html/

    When someone types in "www.maindomain.com/maindomain/", is there a way to have it re-direct to www.maindomain.com?
     
    webeducation, Jun 24, 2009 IP
  2. Guttu

    Guttu Peon

    Messages:
    728
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just save the following code as index.php in the "www.maindomain.com/maindomain/" folder


    
    <?php
    redirect_to_url('../index.php');
    
    function redirect_to_url( $relative_url = 'index.php' ) {
      if ( ( dirname($_SERVER[ 'PHP_SELF' ]) == '\\' || 
    	 dirname($_SERVER[ 'PHP_SELF' ]) == '/' ) ) {
        // Hosted at root.
        header('Location: http://'.$_SERVER[ 'HTTP_HOST' ].'/'.$relative_url);
      } else {
        // Hosted in sub-directory.
        header('Location: http://'.$_SERVER[ 'HTTP_HOST' ].dirname($_SERVER[ 'PHP_SELF' ]).'/'.$relative_url);
      }
      exit;
    }
    ?>
    
    Code (markup):
     
    Guttu, Jun 24, 2009 IP
  3. webeducation

    webeducation Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Guttu, thank you, the code looks really good. I won't get a chance to try it out for a while as I ended up just throwing all of the contents in the /maindomain/ folder and putting them in the root under /public_html/ and of course editing the .htaccess file which works great with the exception that my files are now scattered. I'll give this a shot down the road when I get a chance. Thanks so much once again for the code.
     
    webeducation, Jun 24, 2009 IP