1

I am a little new to the apache vhosts configuration and for educational purposes I wish to set up a domain and a subdomain.

The domain is already set up under the name example.com. Now I want to create a subdomain test.example.com.

Consider the following (desired) directory structure:

- site_com
   - test
       - index.html
   - css
       - gobal.css
   - index.html

I have managed to do this by doing:

<virtualhost *:80>
ServerName test.example.com
ServerAdmin [email protected]
DocumentRoot site_com/test

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

<Directory site_com/test>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

I successfully go to the correct index.html when I go to test.example.com.

Now consider that index.html is a very simple page that contains a relative path to load a css file from the site_com/css directory. by using the following code in test/index.html:

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

However the CSS does not load. The reason is a 404 response. I have verified that the actual directory structure is correct and I have no idea why this behaves like that. I have used webhosts before and there a subdomain is also just a folder in your top domain but everything works perfectly. The stack software I use is called ZPanel.

1 Answer 1

2

You will need to load http://example.com/css/global.css as its for a different domain - the browser doesn't know about the directory structure on your server and cannot link the 2 sites together without a direct URL

3
  • Is there not some way to tell apache that the parent directory (would be root domain) files are available aswell?
    – Limnic
    Jun 6, 2015 at 17:14
  • 1
    You could set up a symlink site_com/test/css that points to site_com/css and have Apache follow symlinks, but it can't serve files outside of its root directory otherwise. Jun 6, 2015 at 17:17
  • 1
    If you did that, you would load /css/global.css rather than ../css/global.css Jun 6, 2015 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.