The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> System Administration
> Apache Development
|
general - Too simple? Not for me!
Discuss Too simple? Not for me! in the Apache Development forum on Dev Shed. Too simple? Not for me! Apache Development forum discussing HTTP Server general topics, configuration, and modules. Apache is an open source web server that runs on multiple platforms.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 1st, 2012, 10:38 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 20 m 19 sec
Reputation Power: 0
|
|
|
general - 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.
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.
|

December 2nd, 2012, 12:27 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
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,
Code:
RewriteRule ^scripts(.*) /path/to/root/myresources/scripts$1 [L]
|

December 2nd, 2012, 11:53 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 20 m 19 sec
Reputation Power: 0
|
|
|
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.
We'll see.
|

December 3rd, 2012, 12:11 AM
|
 |
CSS & JS/DOM Adept
|
|
Join Date: Jul 2004
Location: USA
|
|
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
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 20 m 19 sec
Reputation Power: 0
|
|
|
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
/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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|