Too simple? Not for me!

Discussion in 'Apache' started by jrisken, Dec 1, 2012.

  1. #1
    I have multiple subdomains at BlueHost, all one level down for public_html, that provide identical services for different customers.

    To save myself endless replication of identical javascript and css files, I would like statements of the form

    <link href="scripts/override.css" rel="stylesheet" type="text/css">

    to be redirected up-account to (say) "root/myresources/scripts/override.css"

    There's clearly some way to do this with 'mod_rewrite' or 'alias' of 'follow symlinks' - OR SOMETHING! - but I'm too much of a script kiddie in this area, there are too many ways to go wrong, and I can't find a simple example (probably because it's blindingly obvious to most users!)
    (Oh. and the proposal to use ../ to go levels does not work.)

    So please,

    1. What directive would I write to achieve my purpose?
    2. What file would I put that directive in so that it would get executed?

    Thanks for any help you could give.
     
    jrisken, Dec 1, 2012 IP
  2. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    230
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #2
    You don't need redirection, you can use an absolute path.

    <link href="http://yourmaindomain.com/scripts/override.css" rel="stylesheet" type="text/css">
    Code (markup):


     
    RoseHosting, Dec 2, 2012 IP
  3. jrisken

    jrisken Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I need to end up above public_html, i.e. above the document root of any of my domains.
     
    jrisken, Dec 2, 2012 IP
  4. jrisken

    jrisken Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks, everybody, for the suggestions. Here are two excellent solutions.

    Problem: I want resources such as images and scripts NOT stored in (or under) the document root for a domain. In my case this is because I have multiple domains that all require the same resources. So in the environment of my shared server on BlueHost, a typical site's document root might be at
    /home/myacct/public_html/mysite
    and if I wanted to get a CSS file I would say
    <link href="mycss.css"> and that would require my CSS file to be in the mysite folder. And I'd have to have the identical file in mysite2, mysite3, etc.
    What I'd really like to be able to do is store all such resouces in
    /home/myacct/myresources.

    What people suggested and I tried and found would not work
    a) Use double-dot notation to go above the document root
    <link href="../mycss.css">
    b) Use mod_rewrite in .htaccess
    options +SymlinkIfOwnerMatch
    RewriteRule mycss.css /home/myacct/myresources/mycss.css
    c) Use Alias in .htaccess (available only in httpd.conf - at the server level)

    What does work. There are two solutions. For the sake of simplicity, let's assume that I'm going APPEAR to locate all my resources in a subdirectory of the document root. So my CSS link will look like this:
    <link href="resources/mycss.css">
    But in fact my resources will be in /home/myacct/myresources

    Solution 1: Use ssh and the linux symbolic link command to create a fake subdirectory in the document root of each of your sites
    cd /home/myacct/public_html/mysite
    ln -s /home/myacct/myresources resources

    Solution 2: Use the PHP symlink command to achieve the same effect:
    <?php @symlink("/home/myacct/myresources", "home/myacct/public_html/mysite/resources"); ?>
    If you run this command as part of your regular scripting, it will create the link but then halt processing. Running hte script a second time will throw a warning because the link has already been created, and the @ in front of the command gobbles that warning. As a matter of good practice you should not leave this command in your regular scirpt.

    Well, folks, I spent about 30 hours getting to this point. I hope this will save you at least some of that time.
     
    jrisken, Dec 3, 2012 IP