Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 1st, 2012, 10:38 PM
jrisken jrisken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 jrisken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old December 2nd, 2012, 12:27 AM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,682 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 24 m 24 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
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]

Reply With Quote
  #3  
Old December 2nd, 2012, 11:53 PM
jrisken jrisken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 jrisken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old December 3rd, 2012, 12:11 AM
Kravvitz's Avatar
Kravvitz Kravvitz is online now
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,830 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 17 h 9 m
Reputation Power: 4192
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.
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

Reply With Quote
  #5  
Old December 3rd, 2012, 11:54 AM
jrisken jrisken is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 jrisken User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > general - Too simple? Not for me!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap