I have a hosting account with a domain pointer for one of my websites.

For argument's sake the username on the account is 'chris' and the website is 'foo'.

I'm attempting to use what I thought was a simple link/href to a style sheet that is found in my phpBB directory:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link href="/home/chris/public_html/foo/forum/styles/AutoWidth/theme/normal.css" rel="stylesheet" type="text/css" title="A" />
<title>My Title</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>

The mixed case of that href tag matches exactly the directory structure on the server.

When the page renders, the style sheet is not loaded. Firebug tells me this was the response to trying to get to the style sheet:

The requested URL /home/chris/public_html/foo/forum/styles/AutoWidth/theme/normal.css was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Yes, I realize I can use the URL form for the href, but this is only a small piece -- I have PHP includes I need to reference as well, and I don't want to get into using Curl or turning on any PHP options that allow remote code injection to my site.

Anyone have any idea why that simple absolute path reference in my href tag is not working? If I use relative path (e.g. '../forum') then it works fine. I'm a newbie to this and I've burned up two solid days trying to figure it out.

Just to make sure it's not a permission problem I changed that path and file to 777. Still no joy.

Thanks,
Chris

Recommended Answers

All 9 Replies

Your reference does not tell your browse what server to pull the data from so it assumes your local machine. You need to use a Server based URL which is probably going to be:

http://yourdoamin.com/foo/forum/styles/AutoWidth/theme/normal.css

The absolute path you provided is for scripts run from the command line on the server not http requests.

Try this:
I shortened the file to only directories BELOW doc root.
Apache can only serve files found in or below doc root. All references are relative to that point.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel ="stylesheet" href="/foo/forum/styles/AutoWidth/theme/normal.css" type="text/css" title="A" />
<title>My Title</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>

Thanks for the suggestions. That last one (localhost) gave me an error "Unable to load source" -- so it might be close to the answer. I might actually be dealing with a permission issue since I realize now that the path starting with /home is not open for public read (for good reasons). So this entire idea of absolute reference starting at the root may not be workable.

I did figure out an ugly workaround -- putting symbolic links to the directories that are needed, within the called-from directories where my code is running.

I was also thinking that there might be a way to use mod_rewrite to trap the 404 on not finding those style sheets, and re-directing to the correct URL. I started looking at the documentation for mod_rewrite but I can't claim to even begin to understand how to do something like this, or if it would even work.

-Chris

Hello,

Getting it working for localhost is great for you but when referenced from outside the server it will not work. You were on the right track by setting it up based on the DocumentRoot. Make sure that the file or folder in question has the same group as your apache user (normally apache or nobody) and that the group has read permissions on the file or that the world has read permissions.

-rw-r--r--  bob apache  3967 2010-08-16 13:50 Products.php

Here is the code I use when the stylesheet is in the same dir

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


You mentioned some thing I wanted to check on about home being open. Nice thing about linux is you do not have to have permission to read the directories above a directory to be able to read the ones below it. (For example. As a user I cannot create directories in /home but I can in my subdirectory.) To allow users to execute your php or html scripts they only need read permission for the group your apache application runs under.

On a separate not is there a special reason you are creating public_html sites under the /home/<user> directory instead of using /var/www/html/<sitename> ? I have found over the years it is safer to keep the pages out of the home directory tree and simply put a symbolic link from the users home to the location of the web site.

[root@cwsvr02 html]# ls -la /home/sharpmcn/
total 724
drwx------  5 sharpmcn www    4096 Aug 13  2009 .
drwxr-xr-x 28 root     root   4096 Aug  6 01:37 ..
-rw-r--r--  1 sharpmcn www      33 Aug  6  2009 .bash_logout
-rw-r--r--  1 sharpmcn www     176 Aug  6  2009 .bash_profile
-rw-r--r--  1 sharpmcn www     124 Aug  6  2009 .bashrc
-rw-r--r--  1 sharpmcn www      11 Aug  6  2009 .qmail
-rw-r--r--  1 sharpmcn www  635392 Aug 13  2009 sharp.pub
lrwxrwxrwx  1 root     root     31 Aug  6  2009 www -> /var/www/html/sharpmcnamara.com
[root@cwsvr02 ~]# cd /var/www/html/
[root@cwsvr02 html]# ls -l
drwxr-xr-x  7 jazz     www   4096 Aug 14 10:10 fortworthjazz.com
drwxr-xr-x  3 heaventr www   4096 Mar 31  2009 heavenlytranscription.com
drwxr-xr-x  9 splash   www   4096 May  5 05:54 splashwebeffects.com
drwxrwxr-x 16 txlinux  www  12288 Jul 14 03:23 support
drwxr-xr-x  6 thpadmin www   4096 Sep  2  2008 thehowardspage.org
drwxr-xr-x 19 txlinux  www   4096 Aug 17 04:03 txlinux.com

Since I also hate paging through the httpd.conf file to get to the domains I add this line to the bottom of the httpd.conf and keep my domain info in domains.conf :

Include /etc/httpd/conf/domains.conf

And then my domains.conf only has a sample and the domains and looks like this:

[root@lptp1 smokeshop]# cat /etc/httpd/conf/domains.conf
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
<VirtualHost smokeshop.com:80>
    ServerAdmin rod@txlinux.com
    DocumentRoot /var/www/html/smokeshop.com
    ServerName smokeshop.com
    ErrorLog /var/log/httpd/smokeshop.com-error_log
    CustomLog /var/log/httpd/smokeshop.com-access_log common
</VirtualHost>

My previous example using doc root as the relative root works.
However, permissions must be such that the file is accessible to Apache.
Be sure that the owner/group are consistant with "known good" files.
If you are on a well setup hosted machine, this is rarely an issue.
A typical setup is directories set at octal 755 and files 644.

@rch1231

On a separate not is there a special reason you are creating public_html sites under the /home/<user> directory instead of using /var/www/html/<sitename> ? I have found over the years it is safer to keep the pages out of the home directory tree and simply put a symbolic link from the users home to the location of the web site.

He is probably on a shared hosting server. They often use this configuration to separate the hundreds of accounts that need to log on for maintenance of their specific site. That being said, he has little control over the server directives other than perhaps .htaccess.

JRM, you are correct - your first example does work on my hosting account where I have a single domain hosted.

On my other hosting account where I have a base domain then domain pointers for sub-domains, I can't get it to work. This is where I was testing -- on one of the sub-domains.

I think there is something about the directory structure when sub-domains are involved that I don't understand. It's odd that PHP's getcwd() returns a directory that I thought should work for absolute reference in this case...it does not.

It's good that it works on my other dedicated hosting account though -- that's my production environment.

-Chris

Here's a mistake that I've made myself and found myself bewildered.
If you copied a live site to the sub domain, did you change the base directory settings in the config files?
If the live site was /, the subdomain base would need to be /foo/

Ironically, some things will work, others will not such as in your case.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.