boisterouslobster
boisterouslobster

Reputation: 1293

Apache not recognizing directories other than root

When trying to load anything other than www.example.com (for example, www.example.com/something), I get an error from apache indicating that 'the requested URL /something was not found on this server'.

Any ideas on what the issue may be? I'm running a laravel app on Digital Ocean - LAMP/Ubuntu.

My apache2.conf file (stripped of comments):

Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 300


KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5


User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf


<Directory />
    Options FollowSymLinks
    AllowOverride All
    Require all denied
    RewriteEngine On
    RewriteBase /var/www/html/scheduleify/app/public
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

#<Directory /srv/>
#   Options Indexes FollowSymLinks
#   AllowOverride None
#   Require all granted
#</Directory>


AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>


LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent



IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf


Include /etc/phpmyadmin/apache.conf

EDIT: Also the sites-enabled conf file:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/scheduleify/public

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Upvotes: 0

Views: 1731

Answers (1)

Alana Storm
Alana Storm

Reputation: 166066

Apache is a web server -- its main job is to serve files to the web. If it's telling you there's no file at

http://example.com/foo/baz/bar

then there's no file there. It's working as it should

Laravel is a PHP application that works by running the file index.php. If

http://example.com/
http://example.com/index.php

is rendering correctly via Laravel, that means Laravel is working.

In order to make URLs like

http://example.com/foo/baz/bar

render via Laravel, Laravel includes a .htaccess file in the public folder that redirects most if not all all URLs to index.php. It's this .htaccess file that's responsible for turning

http://example.com/foo/baz/bar

into

http://example.com/index.php/foo/baz/bar

In a working system this happens behind the scenes. i.e. from a user looking at their browser point of view, the URL remains http://example.com/foo/baz/bar

If URLs in the second form are rendering on your server, then it's almost certainly an .htaccess issue. In whichever <Directory node you're configuring your webroot, you want something like this

AllowOverride All

This tells Apache "hey, let the user use a .htaccess file to reconfigure everything you can configure from an .htaccess file. You can find more information about AllowOverride on the apache docs site.

Upvotes: 2

Related Questions