.htaccess from sub-domain to another directory if file not found.

Discussion in 'Apache' started by FFMG, Dec 26, 2008.

  1. #1
    FFMG, Dec 26, 2008 IP
  2. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #2
    ErrorDocument 404 /listoffiles.php

    I think you are NOT allowed in error doc to have full URL but only as above
    that's what I use successfully on my site in some folders
    try
     
    hans, Dec 26, 2008 IP
  3. FFMG

    FFMG Well-Known Member

    Messages:
    1,091
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Thanks, but how would you go back one directory?

    Would:
    
    ErrorDocument 404 ../listoffiles.php
    
    Code (markup):
    Be valid?

    FFMG.
     
    FFMG, Dec 26, 2008 IP
  4. FFMG

    FFMG Well-Known Member

    Messages:
    1,091
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    160
    #4
    
    ErrorDocument 404 ../listoffiles.php
    
    Code (markup):
    Be valid?

    FFMG.[/QUOTE]

    Actually, I just tried and it does not work...

    FFMG
     
    FFMG, Dec 26, 2008 IP
  5. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #5
    subdomain is like domain just different
    your root is
    http://dl.example.com
    and that is where
    /listoffiles.php

    can go and no further because sub.domain is bound to its own root directory

    easiest is to get your /listoffiles.php INTO your sub-domain-directory
    example.com/dl/listoffiles.php

    if you then place above error code line - then you get what you want

    I am sure other people here may have smarter rewrite rules - later after xmas days
     
    hans, Dec 26, 2008 IP
  6. FFMG

    FFMG Well-Known Member

    Messages:
    1,091
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    160
    #6
    In the end I did a bit of work around, not sure if it is the best way.

    In http://dl.example.com I have
    
    ErrorDocument 404 listoffiles.php
    
    Code (markup):
    And in case the user accesses it directly, (because http://dl.example.com/ is actually http://www.example.com/dl/), in http://www.example.com/dl/ I have another.
    
    ErrorDocument 404 listoffiles.php
    
    Code (markup):
    This listoffiles.php simply has
    <?php
    inlcude "../listoffiles.php"
    ?>
    Code (markup):
    while the base listoffiles.php does a redirect to the actual page/site I want to go on my server.

    Not the prettiest, but it works fine as far as my logs tell me.
    FFMG
     
    FFMG, Dec 30, 2008 IP