Access across sub domains

Discussion in 'Apache' started by znoopy, Jul 30, 2010.

  1. #1
    Hi,

    I have a site directory site.com and an alpha directory, alpha.site.com.

    What do I need to do to enable alpha.site.com access to files in the directory for site.com?

    Thanks! :confused:
     
    znoopy, Jul 30, 2010 IP
  2. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #2
    Assuming alpha.site.com is where you are building the next version of the site and you just require it to be able to access the data files from site.com then in PHP you can either use something like include '../site.com/something.php'; or you can use an absolute path e.g. include '/home/youraccount/site.com/something.php';

    I've used PHP as an example because that's what I use but the principle should be the same for other languages.
     
    tolra, Jul 30, 2010 IP
  3. znoopy

    znoopy Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks. To be more precise:

    I want to access images and txt files on the site dir from the alpha dir.

    '/home/youraccount/site.com/something.png' and '/home/youraccount/site.com/something.txt'

    from

    '/home/youraccount/subdomains/alpha/site.com/something.php'

    Thing is, I cant... alpha doesnt get access to site per above currently...
     
    znoopy, Jul 30, 2010 IP
  4. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #4
    If you're using apache and have mod_proxy installed then give the following a go, it needs to be in .htaccess for alpha.site.com:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*) http://atlantichosting.net/$1 [P]
    Code (markup):
    If you don't have mod_proxy then try the following instead:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*) http://atlantichosting.net/$1 [R=302]
    Code (markup):
    In the 1st version if the file doesn't exist then the file is fetched from the site.com domain and returned to the browser as though it came from your alpha.site.com domain.

    In the 2nd version if the file doesn't exist then the browser is redirected to the file on the site.com domain and the data comes from site.com.

    Let me know how you get on.
     
    tolra, Jul 30, 2010 IP
  5. znoopy

    znoopy Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks. Both of them redirects me (the url) to the live site..
     
    znoopy, Jul 30, 2010 IP
  6. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #6
    Odd the [P] version should show the files as coming from the alpha domain, however does the redirecting work for your requirements?
     
    tolra, Jul 30, 2010 IP
  7. znoopy

    znoopy Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Unfortunately not, it currently immediately redirects me from alpha.site.com to site.com (in the browser).
     
    znoopy, Jul 30, 2010 IP
  8. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #8
    Does it redirect no matter if the file exists or not and you take the lines I gave you out of the alpha .htaccess does it still redirect?
     
    tolra, Jul 30, 2010 IP
  9. znoopy

    znoopy Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Yes. Without your lines it doesnt. But then no files from live dir are reachable for the script.
     
    znoopy, Jul 30, 2010 IP
  10. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #10
    Do you have anything else in the .htaccess file apart from the 3 lines from:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*) http://atlantichosting.net/$1 [P]
    Code (markup):
     
    tolra, Jul 30, 2010 IP
  11. znoopy

    znoopy Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I did. Had a closer look and there was some interference going on. Your suggestion works brilliantly now. Thanks!
     
    znoopy, Jul 30, 2010 IP
  12. znoopy

    znoopy Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Oops too quick Im afraid. What it does now is to stay on the alpha URL but actually picks up the scripts from the live dir, even though they exists on alpha..
     
    znoopy, Jul 30, 2010 IP
  13. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #13
    Sorry for the delay I got caught up with other things, give the following a go it should solve the issue of the home page:
    RewriteEngine on
    RewriteCond %{THE_REQUEST} !^[A-Z]+\ /\ HTTP/
    RewriteCond %{REQUEST_URI} !-f
    RewriteRule ^(.*) http://atlantichosting.net/$1 [P]
    Code (markup):
    For anything else I'll need to see both sites so that I can understand what you have.
     
    tolra, Jul 30, 2010 IP
  14. znoopy

    znoopy Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Thanks. It did. I still cant pull files from the live directory though. Strange. I also tried with symbolic links without any luck. With have a look later on. Cheers
     
    znoopy, Jul 30, 2010 IP
  15. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #15
    Not sure what you mean by that, you can't get them via the alpha domain or do you mean via scripting?
    Do you an example of what you are trying to do that isn't working?
     
    tolra, Jul 30, 2010 IP