December 1st, 2012, 10:38 PM
Too simple? Not for me!
I apologize if this is the wrong place or too elementary, but...
I have multiple subdomains at BlueHost, all one level down for public_html, that provide identical services for different customers.
<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.)
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.
December 2nd, 2012, 12:27 AM
In your shoes I would go for symlinks first. Very easy to manage, and the filesystem setup is very logical. Make sure you have Options +FollowSymLinks for your site (like in the .htaccess) and symlink the site's scripts/ to that place under root/.
If that's not possible then Alias, but that's only available in the server config and virtual host. Probably can't do that.
Otherwise a simple RewriteRule can do it. Along with the RewriteEngine,
RewriteRule ^scripts(.*) /path/to/root/myresources/scripts$1 [L]
December 2nd, 2012, 11:53 PM
It's a start
Thanks. Your example sent me back to the drawing board. It does not achieve what I want it to because it will not (at least in my tests) let me redirect things higher up than the document root.
What I really need is an Alias directive, but that's not available in .htaccess.
I had previously used a trick as follows:
<link href="index.php?=someValue"> and then in index.php jumped up a couple of levels and used the 'someValue' to push resources out.
I believe (have not tested 'cause it's late) that this rewrite rule will let me move that trick out of sight:
If I have <link href="myfile.css">, then a rewrite rule that says
RewriteRule (.*).css index.php?theFile=$1.css
will give index .pdp enough info to deliver the desired file.
December 3rd, 2012, 12:11 AM
Welcome to DevShed Forums, jrisken.
Given those limitations, I'd do that myself if I didn't create a separate subdomain for the stylesheets and other resources (which can have certain advantages, like avoiding the overhead of cookies).
One note of caution though. You may want to put some validation in place so that people can't use the script to view the contents of all of your PHP files.
December 3rd, 2012, 11:54 AM
And the best answer is...
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
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
What people suggested and I tried and found would not work
a) Use double-dot notation to go above the document root
b) Use mod_rewrite in .htaccess
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:
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
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.