user14245976
user14245976

Reputation:

Apache/2.4.6 (CentOS) Virtual Host error 404 with directory and files outside root

I'm trying to setup a Virtual Host (let's say "subdomain1.domain.com") on Apache/2.4.6 (CentOS). The web server does not have a hostname, IP address let's say is 55.55.55.55, Apache is listening at port 80. I have a redirect service active and the requests for "subdomain1.domain.com:80" are redirected to http://55.55.55.55/.

DocumentRoot is "/var/www/html" as per httpd.conf.

The website public content is in a directory named "subdomain1" which I'm placing inside the /var/www/html directory. The website code makes use of some JS/CSS which should be in common with the other virtual hosts I would like to create later, so I place the JS/CSS in a directory "libraries" located outside the WebSite Document Root (means, inside "/var/www/html"), and I'm tryng to give them access from the html code by a "../libraries/".

Virtual Host configuration file is a "subdomain1.conf" placed in /etc/httpd/conf.d/" directory, this is the file:

<VirtualHost *:80>
ServerName subdomain1.domain.com
DocumentRoot /var/www/html/subdomain1
</VirtualHost>

Now, with this configuration I can reach the website of Subdomain1 at http://subdomain1.domain.com. The public content of Subdomain1 is reachable, but.. the problem is: all the JS/CSS are not found by Apache and they all return a 404 error. While debugging with the web browser I see the path where Apache is searching the JS/CSS library is "http://55.55.55.55/libraries/" and this returns 404.

Any idea where I'm doing wrong ?

Many thanks ! Mic

Upvotes: 0

Views: 1024

Answers (1)

Afrizal
Afrizal

Reputation: 21

Here are some suggestions from me.

  1. Setting FQDN of your server FQDN

    $ nano /etc/hosts

    55.55.55.55 subdomain1.domain.com subdomain1

  2. Setting your server hostname

    $ nano /etc/hostname

    subdomain1.domain.com

  3. Enable mod_rewrite on the apache webserver

  4. Create an .htaccess file below and save it into the folder /var/www/html/subdomain1/

    < IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] < /IfModule>

Thank you, Afrizal

Upvotes: 0

Related Questions