News:

Click here for Toll-Free Service for your business starting at $2.00 per month

Main Menu

Relative Urls: Can rewrite Resolve Root to = /

Started by doctoreast, February 07, 2007, 04:39:29 PM

Previous topic - Next topic

doctoreast

Hi,
  I'm using php, wrestling with relative paths, and I'm
wondering if there is anything I can do with rewrite
or something, that I can obtain relative / to mean root.
Relative to current, the ../ and ../../ is not working
due to the php includes being called from different files
in different folders.  I'm certain that some here will know
what I'm speaking of.  Right now, I'm using absolute urls,
as it's the only thing that seems to work. 
Thanks in Advance,
East 

brainiac744

Just use the absolute path, I'm pretty sure it's the only way, because mod_rewrite is only going to change paths for things external to the server (as in: not PHP).

That path is:
/fpgs/fpgshttpd/YOURUSERNAME/

doctoreast

brainiac,

  What you speak of isn't absolute, it's root relative. 
Absolute normally refers to http://entireaddress...
This would work, but also would absolute.  Man,
I hate to even think that I'm going to have to
change every freaking link in the site.  I saw this
done before with php or something, resolving /
as account root, but the script had to come up on
every page in the site. 

  One would think that freepgs would have this issue
already resolved, like most hosts do.  It's the member
subfolder/arrangement that screws this up. 

EAst 

brainiac744

No, /fpgs/fpgshttpd/YOURUSERNAME/ IS the absolute path to your account

http://en.wikipedia.org/wiki/Absolute_path
(if you don't believe me)

What you want isn't possible on this (or any shared hosting plan that I know of, unless you're hosting yourself), if I'm understanding you correctly. What you're saying is that you want / to refer to YOUR directory and NOT the actual root directory of the server, right?

OR (just thought of this now)
Are you talking about actual links on your site? If so that's something entirely different and I apologize

doctoreast


Yes, links src/href on my site.  All of my links on stylesheets, includes, and pages think
that / is site root, not server root.  I googled and came up with a few things, as I'm
certain that I've seen this done before.  Is this guy here speaking of javascript or asp?
http://www.geekzilla.co.uk/View35445C1B-E1DA-45C7-AFE5-934988BCBB72.htm

Thanks in Advance,
East

brainiac744

It's talking about asp. Unfortunately that's a windows server type thing, so it won't work here.

Since your url is something.freepgs.com or something.com / should resolve properly. Do you have a link to your site that I could look at because I'm having trouble understanding what your problem is...

doctoreast

#6
brainiac,
   Well, after your comments, I tested it.  It's complicated. 
It does work, except that I was trying to use images from one
domain name for the 2nd domain name also, but that does not
accept the / as root, which is now understandable, expected,
as it is not 2nd domain name's root; it belongs to the first.
The 2nd domain name is a subfolder of the first, and so, at first,
I assumed this would work.  I'm going to copy my images to the
2nd domain name also, and forget about it. 

Follow the white rabbit...
http://www.youtube.com/watch?v=6xhYk9PEmXA&mode=related&search=

Many Thanks,
East


doctoreast

 Using a second domain in a subfolder of main domain, / works
as root for images, but the server wont parse the includes, gets
this error message:



Warning: main() [function.main]: open_basedir restriction in effect. File(/includes/ez2_html-head-meta.html) is not within the allowed path(s): (/tmp/:/fpgs/fpgshttpd/doctoreast/:/fpgs/fpgslogs/68564/:/usr/share/pear/) in /fpgs/fpgshttpd/doctoreast/wholives/index.php on line 11

Warning: main(/includes/ez2_html-head-meta.html) [function.main]: failed to open stream: Operation not permitted in /fpgs/fpgshttpd/doctoreast/wholives/index.php on line 11

brainiac744

With the php includes you'll have to use a relative path, or the absolute path to your directory, which is the one I posted above, because it is aware of the actual directory structure on the server, unlike a web browser.

Just to reiterate, this is that path:
/fpgs/fpgshttpd/USERNAME/OTHER_FOLDERS_HERE

doctoreast

Brain,
  Is this always the case with includes on servers?  I've had this
problem before, but never realized what was going on.  I can't believe
that Ive put so much time into this one.
East

brainiac744

Yes, this is just about universally the case with includes on the server side. (which was what was causing my previous confusion with your topic also)

lotsofish

Quote from: doctoreast on February 07, 2007, 04:39:29 PM
Hi,
  I'm using php, wrestling with relative paths, and I'm
wondering if there is anything I can do with rewrite
or something, that I can obtain relative / to mean root.
Relative to current, the ../ and ../../ is not working
due to the php includes being called from different files
in different folders.  I'm certain that some here will know
what I'm speaking of.  Right now, I'm using absolute urls,
as it's the only thing that seems to work. 
Thanks in Advance,
East 


It will make it easier for you in the long run if you define a variable that holds the path to your scripts and use the variable instead of the full path hardcoded.  So define a variable in a config or include file like $root='/fpgs/fpgshttpd/doctoreast/'; then whenever you need to reference a file using PHP, you would use it as $root.'subfolder/file.php';  If you ever decide to move your script away from your freepgs account, you would only have to update the 1 line instead of searching through all your code.

:)