Androbaut
Androbaut

Reputation: 409

Failing to load resources on apache server

I've got a website I'd like to temporarily host on my VPS, but I've run into a problem.

After creating the '.conf' file in 'sites-available', and activating the site, numerous files aren't being properly linked to.

Here's my .conf configuration:

# domain: mynewsdesk.dev
# public: /var/www/html/mynewsdesk.dev/public

<VirtualHost *:80>
     ServerAdmin [email protected]
     ServerName mynewsdesk.dev
     ServerAlias www.mynewsdesk.dev
     DirectoryIndex index.php
     DocumentRoot /var/www/html/mynewsdesk.dev/
     ErrorLog /var/www/html/mynewsdesk.dev/public/logs/error.log
     CustomLog /var/www/html/mynewsdesk.dev/public/logs/access.log
     combined
</VirtualHost>

In chrome inspector, I see 'Failed to load resource: the server responded with a status of 404 (Not Found)' followed by paths that are clearly incorrect, for example: http://45.79.67.59/mynewsdesk.dev/css/main.css.php.

What settings should I change so that files are pulled from 'mynewsdesk.dev/public/' instead of 'mynewsdesk.dev'?

Upvotes: 2

Views: 2900

Answers (1)

Will
Will

Reputation: 2191

Change your DocumentRoot to be /var/www/html/mynewsdesk.dev/public/.

Alternatively, if you have scripts that you want to run that are outside that directory, and you have mod_rewrite enabled, you can add some rewrite conditions and rules to return files from public and direct all other requests to those scripts.

For example, in your vhost:

RewriteEngine on

RewriteCond          %{DOCUMENT_ROOT}/public%{REQUEST_URI}  -f
RewriteRule  ^(.+)$  %{DOCUMENT_ROOT}/public/$1  [L]

RewriteRule ^(.*)$ index.php?$1 [NC,L,QSA]

Upvotes: 1

Related Questions