Search code examples
codeigniterhttphttp-authentication

Why is my http authentication not working?


I set up http authentication for one of my sites. The web app is built using code igniter and custom URI routing. After changing the .conf file for the site, I got 404 Not Found errors when trying to access any of the pages besides the homepage. For example, navigating to /about, which worked before the http authentication, not gives a 404 with the message:

The requested URL /about was not found on this server.

Apache/2.4.7 (Ubuntu) Server at example.com Port 80

Why is apache sending the request to the '/` directory? The .conf file(slightly adapted for security) under sites-enabled is the following:

<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 example.com  

DirectoryIndex index.php
ServerAdmin webmaster@localhost
DocumentRoot /home/user/codeigniter

# 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 /home/user/logs/codeigniter/error.log
CustomLog /home/user/logs/codeigniter/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

<Directory /home/user/codeigniter/>
    # Options Indexes FollowSymLinks Includes ExecCGI
    # AllowOverride All
    # Require all granted
    AuthType Basic
    AuthName "Beta Site"
    # (Following line optional)
    AuthBasicProvider file
    AuthUserFile /var/www/passwd/passwords
    Require user user
</Directory>


Solution

  • In the Directory definition <Directory /home/user/codeigniter>, you need to change:

    # AllowOverride All
    

    to

    AllowOverride All
    

    and restart apache.

    Without that, the .htaccess file in your document root won't work and you will only be able to access /about through the uri /index.php/about.